ssh客户端会话
SSH is a very common tool for Linux/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.
SSH是Linux / 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服务器和客户端已经提供了这种支持,我们将在本文中讨论这些方法。
客户端修复–每个用户∞ (Client side fixes – per user ∞)
The pro is that users can configure the ssh client by themselves. The con is that every user will need to do it.
优点是用户可以自己配置ssh客户端。 缺点是每个用户都需要这样做。
Linux SSH客户端∞ (Linux ssh client ∞)
Option 1: Add to your ~/.ssh/config
选项1:添加到您的〜/ .ssh / config
# Client will send "keep alive" messages every 60 seconds
# for all server hosts
Host *
ServerAliveInterval 60
Option 2: Add as a command option
选项2:添加为命令选项
$ ssh -o "ServerAliveInterval 60" example.com
腻子 ∞ (PuTTY ∞)
In the Connection category for a session, fill 60 in “Sending of null packets to keep session alive”.
在会话的“连接”类别中,在“发送空数据包以保持会话有效”中填写60。
客户端修复–系统范围内的∞ (Client side fixes – system wide ∞)
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 seconds
ServerAliveInterval 60
服务器端修复–系统范围内的∞ (Server side fixes – system wide ∞)
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 seconds
ClientAliveInterval 298
References:
参考文献:
http://www.howtogeek.com/howto/linux/keep-your-linux-ssh-session-from-disconnecting/
http://superuser.com/questions/699676/how-to-prevent-ssh-from-disconnecting-if-its-been-idle-for-a-while
https://sysadmincasts.com/episodes/39-cli-monday-how-to-keep-your-ssh-sessions-alive
http://brakertech.com/ssh-keeps-disconnecting/
http://www.howtogeek.com/howto/linux/keep-your-linux-ssh-session-from-disconnecting/
http://superuser.com/questions/699676/how-to-prevent-ssh-from-disconnecting-if-its-been-idle-for-a-while
https://sysadmincasts.com/episodes/39-cli-monday-how-to-keep-your-ssh-sessions-alive
http://brakertech.com/ssh-keeps-disconnecting/
翻译自: https://www.systutorials.com/how-to-keep-linux-ssh-session-alive-from-disconnecting/
ssh客户端会话