Я использую Ubuntu 16.04 и OpenSSH на своем VPS. Каждый раз, когда я вхожу в систему через 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
Вы можете использовать ServerAliveInterval в $HOME/.ssh/config
на SSH-клиенте.
Если у вас нет конфигурации в файле конфигурации, вы можете запустить это:
echo "ServerAliveInterval 60" | tee -a ~/.ssh/config
(60 секунд, чтобы поддерживать соединение)