我在 VPS 中使用 Ubuntu 16.04 和 OpenSSH。每次我通过 ssh 登录时,最终都会断开连接。我无法输入任何内容。我需要关闭终端并再次打开它。但是,在尝试再次登录后,我总是收到一条消息ssh: connect to host xxx.xxx.xxx.xxx port 39904: Resource temporarily unavailable
。之后我需要等待至少 2 分钟才能再次登录。
我真的不知道发生了什么。当我看到时/var/log/auth.log
,有很多类似的条目:
May 1 19:41:21 vps20999 sshd[40006]: Received signal 15; terminating.
May 1 19:41:21 vps20999 sshd[40571]: Server listening on 0.0.0.0 port 39904.
指出我与 SSH 失去连接的确切时间。这是一台干净的机器。目前,它只有 OpenSSH 和 UFW。有人知道发生了什么吗?
我正在使用以下 SSH 配置:
# /etc/ssh/sshd_config
# SSH Configuration
# Connection Port
Port 39904
# Protocol Connection
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication
LoginGraceTime 120
PermitRootLogin no
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
MaxStartups 3:50:6
Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin yes
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
# Access only IPv4
AddressFamily inet
# Groups and Users
AllowGroups sshdroplet sftponly
DenyUsers root
DenyGroups root
ClientAliveInterval 120
ClientAliveCountMax 150
答案1
$HOME/.ssh/config
您可以在 SSH 客户端上使用 ServerAliveInterval 。
如果您没有在配置文件上进行配置,您可以运行以下命令:
echo "ServerAliveInterval 60" | tee -a ~/.ssh/config
(保持连接 60 秒)