Common SSH errors

We've gathered the common messages you see when connecting to a Linux server over SSH, from a refused connection and a rejected key to a changed host key warning, legacy algorithms, and disconnects. For each message, you'll find the common cause, what to check, and how to fix it, on your computer and on the server.

Connection not established

  • ssh: connect to host example.com port 22: Connection refused

    Connection refused
    Common cause
    The SSH service isn't running on the server, or it listens on a different port than the one you connected to.
    First check
    The service status on the server, through your server provider's console.

    The server is reachable, but no service accepts connections on the port you used. If SSH listens on another port, add -p with the port number. On the server, through the provider's console, check the service: it is named ssh on Debian and Ubuntu, and sshd on AlmaLinux and Rocky Linux. sudo ss -tlnp shows the listening ports. Recent Ubuntu versions start the service through ssh.socket, so check it too. If the service fails to start after a change, sudo sshd -t shows the faulty line.

    systemctl commands

  • ssh: connect to host example.com port 22: Connection timed out

    No response
    Common cause
    A firewall on the server or along the way filters the port, the address is wrong, or the server is off.
    First check
    The server's IP address, and whether the connection also fails from another network.

    The request got no answer: a firewall filters the port, the address isn't the server's, or the server is off. No route to host usually points to an address that isn't reachable, or to a firewall rule that rejects the connection. Check the IP address, then the server firewall, such as UFW, firewalld, or CSF. A block on your IP address in fail2ban or CSF, after failed logins, has the same effect, so check them too. If your server provider's panel has a firewall, make sure the port is open there as well.

    Check your IP address

  • ssh: Could not resolve hostname server.example.com

    Server name
    Common cause
    Your computer can't translate the server name into an IP address.
    First check
    Connecting to the server's IP address instead of its name.

    ssh found no IP address for the name you entered. Check the spelling, and that the short name you typed is defined in a Host block in ~/.ssh/config, because a name that isn't defined there is sent to DNS as is. ssh -G with the name shows the HostName ssh will actually use. If connecting to the IP address works, check that the name's A record points to the server. After you update a record, it may take time for the change to show on all DNS servers.

    DNS lookup

  • kex_exchange_identification: Connection closed by remote host

    Closed on connect
    Common cause
    The server closed the connection before SSH started, usually due to a connection limit or a temporary address block.
    First check
    The service log on the server at the time of the connection attempt.

    The connection to the port opened, but the server closed it before sending its SSH identification. MaxStartups limits unauthenticated connections, and its default, 10:30:100, starts rejecting some new connections at ten. In recent OpenSSH versions, PerSourcePenalties, on by default, blocks for a set time an address that repeatedly fails authentication or disconnects without logging in. The log then shows a line starting with drop connection and ending with MaxStartups, or a reason starting with penalty. This also happens when a non-SSH service listens on the port.

Host key and algorithms

  • WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

    Host key changed
    Common cause
    The host key differs from the saved one, for example after a server reinstall or moving the address to another server.
    First check
    The host key fingerprint, against a trusted source other than this connection.

    ssh saves the host key in ~/.ssh/known_hosts, and when the server presents a different key, the connection stops. The message warns that someone may be intercepting the connection (man-in-the-middle), so don't delete the saved key before you find the cause. If the change is expected, compare the fingerprint in the message with the one ssh-keygen -lf shows on the server, through the provider's console. Then delete the old entry with ssh-keygen -R and the server name, and connect again. For a port other than 22, write the name in square brackets with the port, for example '[example.com]:2222'.

  • Host key verification failed.

    Host key check
    Common cause
    The host key wasn't verified: it changed, or no one is there to accept the key of a new server.
    First check
    The lines that appear before the message.

    This is the last line when the connection stops at host key verification. If the REMOTE HOST IDENTIFICATION HAS CHANGED warning appears above it, follow the explanation for that warning. The message also appears when a script, a cron job, or a deployment tool connects to a new server and no one is there to accept the key, or when StrictHostKeyChecking yes is set. Connect once manually as the user that runs the script and check the fingerprint, so the key is saved in that user's known_hosts file.

  • no matching host key type found. Their offer: ssh-rsa

    Legacy key type
    Common cause
    The server or device is old and offers only ssh-rsa signatures, which use SHA-1 and are disabled by default.
    First check
    The types listed after Their offer in the message.

    The full message starts with Unable to negotiate with, followed by the address and port. OpenSSH disabled ssh-rsa signatures, based on SHA-1, by default, and old equipment such as routers and switches offers only them. RSA keys still work with SHA-2 signatures. The right fix is to update the software on the other side. As a temporary fix for one server, add -oHostKeyAlgorithms=+ssh-rsa, and for an RSA key login also -oPubkeyAcceptedAlgorithms=+ssh-rsa. The + adds it to the default list. Caution: this algorithm is weak, so never set it for all servers.

  • no matching key exchange method found

    Key exchange
    Common cause
    The other side supports only old key exchange methods, which were disabled for security reasons.
    First check
    The methods listed after Their offer, compared with the list ssh -Q kex shows.

    This message also starts with Unable to negotiate, and it appears mainly when connecting to old devices and software. According to OpenSSH, the best fix is to update the software on the other side. To keep access until then, temporarily add the method the server offers, for example -oKexAlgorithms=+diffie-hellman-group1-sha1, and limit it to this server only in a Host block in ~/.ssh/config. The messages no matching cipher found and no matching MAC found are fixed the same way, with the Ciphers and MACs settings.

Login, keys, and permissions

  • Permission denied (publickey).

    Key not accepted
    Common cause
    The server allows key login only, and the key you sent isn't listed for the user on the server.
    First check
    The ssh -v output: which keys were sent, and for which user.

    The user and server appear before the message, and the parentheses list the login methods the server allows. Check that you logged in with the right user name, and that the public key is in that user's ~/.ssh/authorized_keys file, on a single line. In ssh -v, the Offering public key line shows each key sent. If the key is in another file, point to it with -i. If the right key is sent, check the file permissions and the service log on the server, and for old software with an RSA key, the signature type too.

    SSH key generator

  • Authentication refused: bad ownership or modes for directory

    Permissions on the server
    Common cause
    The home directory, ~/.ssh, or authorized_keys is writable by others or owned by another user.
    First check
    The service log on the server, during the login attempt.

    This message appears in the server log, and your computer shows only Permission denied. With StrictModes on, the default, the server rejects the key when authorized_keys, or a directory above it up to the home directory, is writable by the group or others, or owned by another user. Fix it with chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys, and make sure the user owns both. Remove group and other write access from the home directory. On SELinux distributions, such as AlmaLinux and Rocky Linux, also run restorecon -Rv ~/.ssh.

    Linux file permissions

  • Permission denied (publickey,password).

    Password or key
    Common cause
    Both the key and the password were rejected, or the user name doesn't exist on the server.
    First check
    The Invalid user or Failed password lines in the server log.

    The server allows key and password login, and both failed. In the server log, an Invalid user line means the user name doesn't exist, and a Failed password line means a wrong password. If root can't log in even with the right password, check PermitRootLogin: its default, prohibit-password, lets root log in with a key only. After several failed attempts, fail2ban or CSF may block your address, and then the connection isn't established at all.

  • Too many authentication failures

    Too many attempts
    Common cause
    ssh-agent offers the server many keys, and the server disconnects before the right key gets its turn.
    First check
    The keys loaded in the agent, with ssh-add -l.

    The server limits the authentication attempts per connection (the MaxAuthTries default is 6), and each key sent counts as an attempt. Specify the right key and limit ssh to it only: ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@example.com. For regular use, add the IdentitiesOnly yes and IdentityFile lines to the server's Host block in ~/.ssh/config.

  • WARNING: UNPROTECTED PRIVATE KEY FILE!

    Key permissions
    Common cause
    The private key file is accessible to other users on the computer.
    First check
    The Permissions ... are too open line in the message.

    ssh ignores a private key that others can access, and shows the message It is required that your private key files are NOT accessible by others. Fix it with chmod 600 ~/.ssh/id_ed25519, with your own file name, and set chmod 700 on the ~/.ssh directory. ssh-add won't load such a key into the agent either. This is common after copying a key from a USB drive, a backup, or another computer.

  • Bad owner or permissions on /home/user/.ssh/config

    config file permissions
    Common cause
    The ~/.ssh/config file is writable by the group or others, or owned by another user.
    First check
    The file's owner and permissions, with ls -l ~/.ssh/config.

    ssh refuses to read a config file that another user can change, and stops right away. According to the OpenSSH documentation, the file must be readable and writable by the user, and not writable by others. Fix it with chmod 600 ~/.ssh/config, and make sure your user owns the file. The message is common after copying the file from a backup or another account, or after giving the whole directory overly broad permissions.

  • administrators_authorized_keys on a Windows server

    Windows server
    Common cause
    For an admin account, OpenSSH on Windows reads keys from a shared file, not from the file in the user profile.
    First check
    Whether the key is in C:\ProgramData\ssh\administrators_authorized_keys.

    According to Microsoft, for a member of the Administrators group, add the public key to administrators_authorized_keys in C:\ProgramData\ssh, not to authorized_keys in the profile. Only the Administrators group and SYSTEM may have access to the file. Set this in PowerShell as an administrator: icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F". On a non-English system, Microsoft recommends the group SID, *S-1-5-32-544, instead of its name.

  • PuTTY key in a ppk file

    PuTTY
    Common cause
    Each SSH program stores keys in its own format, so a PuTTY key doesn't load directly in ssh.
    First check
    The key's file extension.

    According to the PuTTY documentation, a key created in one program can't be used right away in another. To use a ppk key with ssh, load it in PuTTYgen and choose Export OpenSSH key from the Conversions menu. In the other direction, Import key in the same menu loads an OpenSSH key, which you then save as a ppk file. Copy the server's public key from the Public key for pasting into OpenSSH authorized_keys file box, and make sure it is saved in authorized_keys on a single line. Set chmod 600 on the exported file.

Disconnects

  • client_loop: send disconnect: Broken pipe

    Idle disconnect
    Common cause
    The connection was cut along the way, usually by a router or firewall that closes idle connections.
    First check
    Whether the disconnect happens after a fixed period without typing.

    The connection was cut while no traffic passed, and ssh found out only when it tried to send data. ServerAliveInterval sends the server a message inside the encrypted connection after the set number of seconds without data, so the connection isn't treated as idle. In ~/.ssh/config, in the server's Host block or in Host *, add ServerAliveInterval 60 and ServerAliveCountMax 3. On the server side, ClientAliveInterval does the same toward clients. For long work, tmux or screen keep the session alive after a disconnect.

    tmux shortcuts

  • Timeout, server example.com not responding.

    Server not responding
    Common cause
    ServerAliveInterval is set, and the server didn't answer the number of messages set in ServerAliveCountMax.
    First check
    Your internet connection's stability and the load on the server.

    ssh dropped the connection itself, because the server didn't answer the number of messages set in ServerAliveCountMax, which defaults to 3. With ServerAliveInterval 60, the disconnect comes after about three minutes without an answer. The cause is usually a network drop, switching between Wi-Fi networks, or a very busy server. If the message keeps appearing on a stable network, check the server load and the service log.

  • Connection to example.com closed by remote host.

    Server closed the connection
    Common cause
    The server ended the connection, for example on a reboot or because of ClientAliveInterval.
    First check
    The service log on the server at the time of the disconnect, and the time since the last boot, with uptime.

    The server closed the connection on purpose. Common causes are a server reboot, the ClientAliveInterval and ClientAliveCountMax settings, which disconnect an unresponsive client, or a shell time limit, such as the TMOUT variable. If the connection closes right after login, check that the user's shell exists and that its startup files, such as ~/.bashrc, don't run exit. The service log on the server shows the reason.

Where to start

Run the connection with the -v option, which shows the stage where it fails. You can use up to three v's for more detail:

Bash
ssh -vvv user@example.com

The Connection established line shows that the connection to the port was made. The Offering public key line shows each key sent to the server, and the Authentications that can continue line shows the login methods the server still allows. The following command shows the settings that will actually apply to the connection, after ~/.ssh/config is read:

Bash
ssh -G example.com | grep -Ei '^(hostname|user|port|identityfile) '

Checks on the server

When you have no SSH access, run the checks through the console your server provider offers in its control panel. On Debian and Ubuntu, the service is named ssh, and on AlmaLinux and Rocky Linux it is named sshd. These commands show the latest lines in the service log:

Bash
sudo journalctl -u ssh -n 50 --no-pager
sudo journalctl -u sshd -n 50 --no-pager

When the server also keeps logs in files, login attempts are written to /var/log/auth.log on Debian and Ubuntu, and to /var/log/secure on AlmaLinux and Rocky Linux. Following the log while you try to connect from another window shows the exact reason for the failure:

Bash
sudo tail -f /var/log/auth.log
sudo tail -f /var/log/secure

In recent OpenSSH versions, some log lines are written under the process name sshd-session rather than sshd, so filter by the service name, not the process name. sshd -t checks the configuration file and shows errors, and sshd -T shows the settings the service actually uses, including the sshd_config.d files:

Bash
sudo sshd -t
sudo sshd -T | grep -Ei '^(port|permitrootlogin|passwordauthentication|pubkeyauthentication|maxauthtries|maxstartups) '

The following command shows the host key fingerprint, to compare with the warning on your computer:

Bash
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

When your address is blocked

After failed login attempts, fail2ban or CSF may block your IP address. From your server provider's console, or from a connection from another address, unblock the address in fail2ban:

Bash
sudo fail2ban-client set sshd unbanip 203.0.113.10

In CSF, csf -g shows which rules the address appears in. Remove a temporary block with csf -tr, and a permanent block with csf -dr:

Bash
sudo csf -g 203.0.113.10
sudo csf -tr 203.0.113.10
sudo csf -dr 203.0.113.10

Before you change sshd_config, keep an SSH session open, and test logging in from a new window before you close it. That way, a configuration mistake won't lock you out of the server.

Did you know?

On a Linux VPS, you connect over SSH with full root access, so you can run every check on this page directly on the server, from the service log to permissions and the firewall.

Linux VPS plans

SSH errors FAQ

What should I check when I can't connect to a server over SSH?

Start with the message on your computer, and run the connection again with ssh -v to see the stage where it fails. Connection refused and Connection timed out point to the service, the port, or the firewall. Permission denied points to the user name, the key, or the permissions on the server. On the server itself, through your server provider's console, the SSH service log shows the exact reason.

How do I know which SSH key was sent to the server?

Run the connection with ssh -v, and look in the output for the Offering public key lines, which show each key sent, and the Server accepts key line, which appears when the server accepts a key. ssh-add -l shows the keys loaded in ssh-agent. To send a single key only, specify it with -i and add -o IdentitiesOnly=yes.

Why does my SSH connection drop after a period of inactivity?

Routers and firewalls sometimes close connections that carry no traffic for a while, and the connection breaks with the message Broken pipe. Add the line ServerAliveInterval 60 to ~/.ssh/config, and ssh will send the server a small message every idle minute, so the connection stays open. For long work, tmux or screen keep your session alive even when the connection drops, and you continue from the same point the next time you log in.

What do I do when a host key change warning appears after reinstalling the server?

Reinstalling the server creates new host keys, so ssh detects that the key differs from the one you saved and stops the connection. On the server, through the console, check the fingerprint with ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub, and compare it with the one in the message. If they match, delete the old entry with ssh-keygen -R and the server name or IP address, and connect again.

Can I use a key created in PuTTY with the ssh command?

Yes. Open the key in PuTTYgen, choose Export OpenSSH key from the Conversions menu, and save the file in ~/.ssh. After you set chmod 600 on the file, connect with ssh -i and the file name. The public key stays the same, so nothing needs to change on the server.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement