0

I'm using Ubuntu 16.04 and OpenSSH in my VPS. Everytime I log in via ssh, eventually connection is lost. I can't type anything. I need to close terminal and open it again. But, after try to login again, I always get a message ssh: connect to host xxx.xxx.xxx.xxx port 39904: Resource temporarily unavailable. And after that I need to wait at least 2 minutes before be able to login again.

I really don't know what is going on. When I saw /var/log/auth.log, there was a lot of entries similar to:

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.

Pointing to exact time when I lose connection with SSH. It is a clean machine. It only has, for now, OpenSSH and UFW. Does someone know what is happening?

I'm using the following SSH configurations:

# /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
  • "ClientAliveInterval 120"--Is your connection cut each time you do nothing for 2 minutes? – George Y May 02 '20 at 06:20
  • The ClientAliveInterval configuration will cut my connection after 120 seconds, but ClientAliveCountMax will send an empty package 150 times before cut the connection based in interval. Anyway, I'm losing connection even with activity. – caiquearaujo May 02 '20 at 22:51

1 Answers1

0

You can use ServerAliveInterval in $HOME/.ssh/config on SSH client.

If you have no configuration on config file, You can run this:

echo "ServerAliveInterval 60" | tee -a ~/.ssh/config

(60 seconds to keep the connection alive)