Solve the problem of ssh remote login and automatic exit after timeout

ssh remote login server, if there is no operation for a period of time, it will be forced to go offline. This improves the security of remote operation and maintenance to a certain extent. But if the time is set too short, it will often cause inconvenience.
In order to solve this problem, the following settings need to be made:
Method 1: Solve through server configuration
1. Set the periodic retry of ssh

vim /etc/ssh/sshd_config 
#server每隔60秒发送一次请求给client,然后client响应,从而保持连接
ClientAliveInterval 60
#server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应
ClientAliveCountMax 3

2. Modify the expiration time of the shell.
If the session times out, there will be a prompt similar to the following

timed out waiting for input: auto-logout

Generally, it is because Linux has set the shell to automatically disconnect when there is no input for a long time.
This needs to modify the /etc/profile file.

vi /etc/profile

Check if there is the following content in the file, if so, change the value to 0, or comment out this line with # (this value is the number of seconds for the timeout, at this time 100 is 100 seconds, if it is changed to 0, it will not time out. You can also to a larger value)

export TMOUT=100

Save the file, run the following command to reload the configuration file

source /etc/profile

Method 2: Solve through client settings
There are different setting methods depending on the client used, which will not be described in detail here.

Guess you like

Origin blog.csdn.net/wangjm1982/article/details/128832868