首页 > 解决方案 > 连接到/从 Ubuntu 18.04 时禁用 SSH 超时

问题描述

我在 Windows 上使用 putty 将 ssh 连接到我的 Digitaloccean 液滴,但 ssh 会话将在短暂不活动后过期。我需要什么配置来延长会话超时?

标签: sshtimeoutubuntu-18.04

解决方案


您需要在 2 个地方设置配置:TESTED WORKING

客户端配置:

- 打开文件 /etc/ssh/ssh_config 并将指令 ServerAliveInterval 设置为类似 100 的值,例如:

# other configs
ServerAliveInterval 100

这会导致您的 SSH 客户端每 100 秒发送一次保持活动消息,以便服务器不会断开您的连接。

服务器配置

- 打开文件 /etc/ssh/sshd_config 并在文件末尾添加这些配置,以确保它们不会被后面的行覆盖:

# other configs
ClientAliveInterval 600
TCPKeepAlive yes
ClientAliveCountMax 10

这些是保守的设置,将使您的 SSH 服务器仅在 (600 * 10 = 6000) 秒的用户不活动后断开连接。如果您需要更多,请自定义这些。

重新启动 ssh 服务器以使更改生效:

$ sudo /etc/init.d/ssh restart

资料来源:http: //queirozf.com/entries/disabling-ssh-timeout-when-connecting-to-from-ubuntu


推荐阅读