1.针对所有用户

  1. vim /etc/profile
  2. export TMOUT=900 # 设置闲置时间为15分钟,单位为秒;如果没有此行则直接添加进去

source /etc/profile 立即生效

2.针对特定用户(如针对tenguwang)

  1. cd /home/tenguwang/
  2. vim .bash_profile vim .bashrc
  3. export TMOUT=900

source /home/chen/.bash_profile 或 source /home/chen/.bashrc

3.通过修改ssh的配置文件来实现

  1. vim /etc/ssh/sshd_config
  2. 找到以下两行:
  3. ClientAliveInterval 60
  4. ClientAliveCountMax 5

systemctl restart sshd

这种方法对除了root之外的所有用户都是60秒登录超时,自动登出。第一行表示每60秒检测一次,第二行表示检测到5次不活动就断开连接。