Solve the problem of disconnecting after being idle for too long after ssh login

When we connect to the server through the terminal, when the mouse and keyboard are not operated for a long time, the server will be disconnected automatically. We still need to reconnect, which is very troublesome. To summarize the methods to solve this problem
1.
Modify /etc/ssh /sshd_config configuration file, find ClientAliveCountMax (unit is minutes), modify the value you want,
execute service sshd reload 
method 2.
Find the .ssh directory of the user where you are, such as the root user, the directory is in:
/root/.ssh/
in this directory Create a config file
vi /root/.ssh/config and
add the following sentence:
ServerAliveInterval 60
saves and exits, restarts the root user's shell, and then sshs the remote server, it
will not be disconnected due to long-term operations. After adding this sentence, the ssh client will automatically communicate with the ssh server every
once in a while, so long-term operations will not be disconnected.
Method 3.
Modify the /etc/profile configuration file
# vi /etc/profile
add: TMOUT=1800
, so that it will automatically LOGOUT if there is no operation for 30 minutes.
Method 4.
Use expect to simulate keyboard actions, and simulate a keyboard response within the idle time. Save the following code as xxx, and use expect to execute
#!/usr/bin/expect  
set timeout 60  
spawn ssh user@host   
      interact {          
            timeout 300 {send "\x20"}  
      } 
expect xxx
and then enter the password according to the prompt, so that a space (\x20) will be automatically typed every 300 seconds, and the specific time interval can be set according to the specific situation.
Method 5.
If you connect through a tool under Windows, you can set it to
secureCRT:
Options->Session Options->Terminal->Anti-idle->Check Send protocol NO-OP

(Chinese version: Options->Session Options->Terminal->Anti-idle->Send Protocol NO-OP)

The default setting time is 60 seconds later, as long as it is less than the time limit for automatic disconnection.

putty: putty -> Connection -> Seconds between keepalives ( 0 to turn off ), default is 0, change to 300.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326137526&siteId=291194637