本文共 2078 字,大约阅读时间需要 6 分钟。
ssh客户端会话
is a very common tool for /Unix platforms. One annoying problem when using SSH is that the connection may get disconnected if the SSH connection is idle for some time under common configurations. Users may run an infinite loop like while true; do uptime; sleep 30; done
when there is no work to be done in a SSH session. There are better ways as SSH servers and clients already provide such support and we will discuss these methods in this post.
是 / Unix平台上非常常用的工具。 使用SSH时的一个烦人的问题是,如果在常规配置下SSH连接空闲一段时间,则连接可能会断开连接。 用户可能会像while true; do uptime; sleep 30; done
那样运行无限循环while true; do uptime; sleep 30; done
while true; do uptime; sleep 30; done
while true; do uptime; sleep 30; done
的时候没有一个SSH会话工作要做。 有更好的方法,因为SSH服务器和客户端已经提供了这种支持,我们将在本文中讨论这些方法。
The pro is that users can configure the ssh client by themselves. The con is that every user will need to do it.
优点是用户可以自己配置ssh客户端。 缺点是每个用户都需要这样做。
Option 1: Add to your ~/.ssh/config
选项1:添加到您的〜/ .ssh / config
# Client will send "keep alive" messages every 60 seconds # for all server hostsHost * ServerAliveInterval 60
Option 2: Add as a command option
选项2:添加为命令选项
$ ssh -o "ServerAliveInterval 60" example.com
In the Connection category for a session, fill 60 in “Sending of null packets to keep session alive”.
在会话的“连接”类别中,在“发送空数据包以保持会话有效”中填写60。
The above methods can also be applied for all users on the system.
以上方法也可以应用于系统上的所有用户。
Add to /etc/ssh/ssh_config
添加到/ etc / ssh / ssh_config
# Client will send "keep alive" messages every 60 secondsServerAliveInterval 60
The SSH server can be configured to send keep alive messages to avoid idle session being got disconnected so that users will not need any special configurations.
可以将SSH服务器配置为发送保持活动消息,以避免断开空闲会话,从而使用户不需要任何特殊配置。
Add to /etc/ssh/sshd_config
添加到/ etc / ssh / sshd_config
# Server will send "keep alive" messages every 60 secondsClientAliveInterval 298
References:
参考文献:
翻译自:
ssh客户端会话
转载地址:http://lmlwd.baihongyu.com/