保持 SSH 会话处于活动状态 [英] Keep SSH session alive
问题描述
我使用 ssh -p8520 username@remote_host
登录远程服务器.
I use ssh -p8520 username@remote_host
to login remote server.
问题:
当我在工作场所时,它始终处于连接状态并正常工作.不幸的是,在我从家里连接到远程服务器后,终端在 10 - 15 分钟内冻结.
It is always connected and works properly when I am in the work place. Unfortunately, terminal freezes in 10 - 15 minutes after I connected with the remote server from home.
控制台上没有错误/超时报告,但光标不能再移动了.
There's no error/timeout report on the console but the cursor cannot move any more.
输入w查看登录用户时,有一些僵尸登录用户,需要手动杀掉.
When enter w to check the login users, some zombies login users are there, and I have to kill them manually.
这很烦人.谁能帮我?
推荐答案
在服务器端运行的 ssh 守护进程 (sshd),如果客户端进入静默状态(即不发送信息),则会关闭来自服务器端的连接).为防止连接丢失,请指示 ssh 客户端不时向服务器发送生命迹象信号.
The ssh daemon (sshd), which runs server-side, closes the connection from the server-side if the client goes silent (i.e., does not send information). To prevent connection loss, instruct the ssh client to send a sign-of-life signal to the server once in a while.
此配置在文件$HOME/.ssh/config
中,如果文件不存在则创建该文件(配置文件不能是全局可读的,所以运行chmod 600 ~/.ssh/config
创建文件后).每隔例如发送信号四分钟(240 秒)到远程主机,将以下内容放入该配置文件中:
The configuration for this is in the file $HOME/.ssh/config
, create the file if it does not exist (the config file must not be world-readable, so run chmod 600 ~/.ssh/config
after creating the file). To send the signal every e.g. four minutes (240 seconds) to the remote host, put the following in that configuration file:
Host remotehost
HostName remotehost.com
ServerAliveInterval 240
要为所有主机发送keep-alive信号,在配置文件中放置以下内容:
To enable sending a keep-alive signal for all hosts, place the following contents in the configuration file:
Host *
ServerAliveInterval 240
这篇关于保持 SSH 会话处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!