I’m the type of geek that has an SSH client open at all times, connected to my most frequently used servers so that I have instant access for monitoring and anything else. As such, it irritates me greatly when I get disconnected, so I’m sharing a few methods for keeping your session alive.
我是一直在打开SSH客户端并连接到我最常用的服务器的怪胎,这样我就可以立即进行监视和其他操作。 因此,当我断开连接时,这会极大地激怒我,所以我分享了一些使您的会话保持活动状态的方法。
You can configure the ssh client to automatically send a protocol no-op code code every number of seconds so that the server won’t disconnect you. This is setting is sometimes referred to as Keep-Alive or Stop-Disconnecting-So-Much in other clients.
您可以将ssh客户端配置为每隔几秒钟自动发送一个协议无操作码代码,以使服务器不会断开您的连接。 在其他客户端中,此设置有时称为“保持活动状态”或“因此而断开连接”。
Global Configuration
全局配置
Add the following line to the /etc/ssh/ssh_config file:
将以下行添加到/ etc / ssh / ssh_config文件中:
ServerAliveInterval 60
ServerAliveInterval 60
The number is the amount of seconds before the server with send the no-op code.
该数字是服务器发送无操作码之前的秒数。
Current User Configuration
当前用户配置
Add the following lines to the ~/.ssh/config file (create if it doesn’t exist)
将以下行添加到〜/ .ssh / config文件(如果不存在则创建)
Host * ServerAliveInterval 60
主机* ServerAliveInterval 60
Make sure you indent the second line with a space.
确保在第二行缩进一个空格。
Per-Host Configuration
每主机配置
If you only want to enable keep alive for a single server, you can add that into the ~/.ssh/config file with the following syntax:
如果只想为单个服务器启用保持活动状态,则可以使用以下语法将其添加到〜/ .ssh / config文件中:
Host *hostname.com ServerAliveInterval 60
主机* hostname.com ServerAliveInterval 60
Works quite well, hope it helps somebody else out there.
效果很好,希望能对其他人有所帮助。
翻译自: https://www.howtogeek.com/howto/linux/keep-your-linux-ssh-session-from-disconnecting/