ssh客户端会话_如何保持Linux SSH会话不断开连接-服务器和客户端修复

SSH在Linux/Unix平台广泛使用,但空闲一段时间可能断开连接。可以通过修改客户端(如Linux SSH配置或PuTTY设置)或服务器端(如sshd_config)配置来保持会话活跃,避免断开连接。
摘要由CSDN通过智能技术生成

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.

SSHLinux / 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。

putty-keep-alive.png

客户端修复–系统范围内的 (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客户端会话

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值