export TMOUT=0不生效
时间: 2023-09-30 11:06:06 浏览: 94
如果您在终端中设置了 "export TMOUT=0",但是该设置没有生效,可能是因为您在一个非交互式的 shell 中运行该命令。例如,如果您在一个 shell 脚本中设置了该变量,那么该变量只会在脚本中生效,而不会在您打开的终端中生效。
另外,如果您的系统管理员在 /etc/profile 或 /etc/bashrc 文件中设置了 TMOUT 变量,那么您在自己的 shell 配置文件中设置该变量可能会被覆盖。您可以通过在您的 shell 配置文件中添加以下行来禁用系统范围的 TMOUT 设置:
```
unset TMOUT
```
这将删除系统范围中的 TMOUT 变量,并允许您在自己的 shell 中设置 TMOUT 变量。
相关问题
/etc/profile文件中export TMOUT=0
如果在`/etc/profile`文件中设置`export TMOUT=0`,则表示禁用自动退出功能,即无论用户是否有操作,都不会自动退出。这通常用于需要长时间保持登录状态的场景,例如服务器维护或特殊应用场景等。
需要注意的是,如果你禁用了自动退出功能,那么可能会存在安全隐患,因为如果用户长时间不活动,其他人可能会接管他的终端会话。因此,在启用自动退出功能时,应该根据实际情况设置合适的超时时间,以确保系统安全。
if grep -q "auth required pam_wheel.so group=wheel" /etc/pam.d/su then sed -i '/auth required pam_wheel.so group=wheel/s/^#//' /etc/pam.d/su else echo 'auth required pam_wheel.so group=wheel' >> /etc/pam.d/su fi if grep -q "export TMOUT=300" /etc/profile then sed -i '/export TMOUT=300/s/^#//' /etc/profile else echo 'export TMOUT=300' >> /etc/profile fi
以下是将这些命令转换为Python代码的示例:
```python
import subprocess
su_pam_file = '/etc/pam.d/su'
wheel_auth_line = 'auth required pam_wheel.so group=wheel\n'
with open(su_pam_file, 'r') as file:
content = file.read()
if 'auth required pam_wheel.so group=wheel' in content:
content = content.replace('#auth required pam_wheel.so group=wheel', 'auth required pam_wheel.so group=wheel')
else:
content += wheel_auth_line
with open(su_pam_file, 'w') as file:
file.write(content)
profile_file = '/etc/profile'
tmout_line = 'export TMOUT=300\n'
with open(profile_file, 'r') as file:
content = file.read()
if 'export TMOUT=300' in content:
content = content.replace('#export TMOUT=300', 'export TMOUT=300')
else:
content += tmout_line
with open(profile_file, 'w') as file:
file.write(content)
```
上述代码首先打开`/etc/pam.d/su`文件,并读取其内容。如果文件中存在`auth required pam_wheel.so group=wheel`行,则将其注释去除,否则将该行添加到文件末尾。
然后,打开`/etc/profile`文件,并读取其内容。如果文件中存在`export TMOUT=300`行,则将其注释去除,否则将该行添加到文件末尾。
请确保你具有足够的权限来执行这些操作,并将需要修改的PAM文件路径和需要修改的profile文件路径正确添加到`su_pam_file`和`profile_file`变量中。运行代码后,命令将被执行。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)