Skip to main content

SSH Connection Errors

If you encounter issues connecting to a server, perform diagnostics. After performing diagnostics, you can resolve some frequently occurring errors yourself.

Identify a connection issue

If connection errors occur when connecting via SSH or if you need to check which key is used for authentication, start the connection in debug mode:

ssh -vvv <username>@<ip_address>

Specify:

  • -vvv — a flag to enable debug mode, which allows you to trace the entire SSH connection setup process;
  • <username> — a username (login). You can view it in the control panel: in the top menu, click ProductsDedicated ServersServers → server page → Operating System tab → Login field;
  • <ip_address> — public IP address of the server. You can view it in the control panel: in the top menu, click ProductsDedicated ServersServers → server page → Operating System tab → IP.

Information about the SSH connection process and any occurring connection issues will appear in the response.

Connection issues

ErrorReasonSolution
Connection timed outConnection timed out
Warning: Identity file /home/user/.ssh/authorized_keys not accessible: No such file or directoryThe client private key is missing or inaccessible
Permission denied (publickey)Server rejected the connection
ssh: connect to host 203.0.113.10 port 22: Connection refusedPort 22 is not accepting connections

Check for the SSH key file

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. Check for the .ssh directory and the authorized_keys file:

    ls -la ~/.ssh/

    Information about the files in the .ssh directory will appear in the response. For example:

    drwx------ 2 user user 4096 Jul 16 10:15 .
    drwxr-x--- 18 user user 4096 Jul 16 09:50 ..
    -rw------- 1 user user 743 Jul 16 10:10 authorized_keys

    Here, authorized_keys is a file containing public SSH keys that are allowed to connect to the server.

  4. Display the contents of the authorized_keys file:

    cat ~/.ssh/authorized_keys

    One or more public SSH keys will appear in the response. For example:

    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP... user@example
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... admin@example

    Ensure that the SSH key corresponds to the private key used on the client.

  5. If the .ssh directory or authorized_keys file does not exist, or the requested public key is not in the file, place the SSH key on the server.

Configure access rights

The SSH server strictly checks user rights for the ~/.ssh directory and the ~/.ssh/authorized_keys file. If the rights are too open, the SSH connection cannot use the keys, even if they are specified correctly.

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. Check rights for the ~/.ssh directory:

    ls -ld ~/.ssh

    Information about rights for the ~/.ssh directory will appear in the response. For example:

    drwx------ 2 username username 4096 Oct 24 10:00 /home/user/.ssh

    Where:

    • drwx------ — object type and the rights systems users have for it, where:

      • d — object type: directory;
      • rwx — owner rights: read, create, and delete files in the directory, access to the directory;
      • --- — no group rights. Group members cannot read, write to, or enter the directory;
      • --- — no rights for other system users;
    • the first username value — user with owner rights;

    • the second username value — user group. Usually the same as the username.

    The rights for the ~/.ssh directory correspond to the 700 code: read, create, and delete files in the directory, access to the directory.

  4. If the rights for the ~/.ssh directory differ in step 3, set the correct rights:

    chmod 700 ~/.ssh

    Where:

    • 7 — owner rights: read, create, and delete files in the directory, access to the directory;
    • 0 — no group rights;
    • 0 — no rights for other system users.

    If successful, the command will not display any output.

  5. If the owner of the ~/.ssh directory is incorrect, change it:

    sudo chown -R <username>:<user_group> ~/.ssh

    Specify:

    • <username> — name of the user you connect to the server with via SSH;
    • <user_group> — user group, usually the same as the username. You can view it using the id <username> command, where <username> is the username.
  6. Check rights for the ~/.ssh/authorized_keys file:

    ls -l ~/.ssh/authorized_keys

    Information about rights for the ~/.ssh/authorized_keys file will appear in the response. For example:

    -rw------- 1 username username 234 Oct 24 10:00 /home/username/.ssh/authorized_keys

    Where:

    • -rw- — object type and the rights systems users have for it, where:

      • -~/.ssh/authorized_keys object type: regular file;
      • rw- — owner rights: read and write;
      • --- — no group rights;
      • --- — no rights for other system users;
    • the first username value — user with owner rights;

    • the second username value — user group. Usually the same as the username.

    The rights for the ~/.ssh/authorized_keys file correspond to the 600 code: read and write.

  7. If rights for the ~/.ssh/authorized_keys file differ in step 6, set the correct rights:

    sudo chmod 600 ~/.ssh/authorized_keys

    Where:

    • 6 — owner rights: read and write;
    • 0 — no group rights;
    • 0 — no rights for other system users.

    If successful, the command will not display any output.

Check SSH service status

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. Check the sshd service status:

    systemctl status sshd

    Information about the sshd service status will appear in the response. For example:

    Active: active (running)
  4. If the sshd service is stopped, restart it:

    systemctl start sshd

Check SSH port

By default, the SSH server accepts connections on port 22.

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. Check which ports the sshd service is waiting for incoming connections on:

    ss -tlnp | grep sshd

    Information about the ports that the sshd service accepts connections on will appear in the response. For example:

    LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1023,fd=3))
    LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1023,fd=4))

    Here, 22 is the port on which the SSH server accepts connections.

    If the output is empty, the sshd service is not running or is not accepting connections.

  4. Check which port is specified in the SSH configuration:

    sshd -T | grep ^port

    Information about the SSH server ports will appear in the response. For example:

    port 2222
  5. If the SSH ports in steps 3 and 4 do not match, restart the sshd service:

    systemctl restart sshd
  6. If the SSH port on the server has been changed, for example to 2222, you must specify it when connecting:

    ssh -p <port> <username>@<ip_address>

    Specify:

    • <port> — SSH port;
    • <username> — username (login). You can view it in the control panel: in the top menu, click ProductsDedicated ServersServers → server page → Operating System → field Login;
    • <ip_address> — public IP address of the server. You can view it in the control panel: in the top menu, click ProductsDedicated ServersServers → server page → Operating System → field IP.

Check firewall settings

Ensure that incoming connections to the SSH port are allowed by firewall rules.

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. For diagnostics, temporarily turn off the firewall and test the connection:

    3.1. Turn off the firewall:

    systemctl stop firewalld

    3.2. Connect to the server via SSH. If you can connect, check the firewall rules.

    3.3. After finishing diagnostics, turn on the firewall:

    systemctl start firewalld
  4. Check iptables rules:

    iptables -L -n -v

    A list of rules will appear in the response. For example:

    Chain INPUT (policy DROP 120 packets, 7200 bytes)
    pkts bytes target prot opt in out source destination
    145 8700 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
    80 4800 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0

    Here, ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 is a rule that allows connections to port 22.

  5. If iptables policies for port 22 are set to DROP or REJECT, change the firewall configuration to allow incoming connections to port 22.

  6. Try connecting via SSH again.

Check SSH configuration on the server

If a Permission denied (publickey) error occurs when connecting or if the server does not offer key authentication, check the SSH server settings.

  1. Load the server in recovery and diagnostic mode.

  2. Connect to the server via the KVM console.

  3. Open the /etc/ssh/sshd_config configuration file with the vi text editor:

    vi /etc/ssh/sshd_config
  4. Ensure that the configuration contains the following parameters:

    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys

    Where:

    • PubkeyAuthentication — when set to yes, this enables authentication using SSH keys;
    • AuthorizedKeysFile — path to the file containing the public SSH key.
  5. If the PubkeyAuthentication and AuthorizedKeysFile parameters are missing, add them.

  6. Exit the vi text editor with your changes saved:

    :wq
  7. Optional: if you added parameters to the configuration file in step 5, check it for errors:

    sshd -t

    If the output is empty, the configuration is correct.

  8. If you added parameters to the configuration file in step 5, restart the SSH service:

    systemctl restart sshd

Check basic firewall rules

The basic firewall processes each packet in isolation — it does not remember established connections and does not track TCP session state. When analyzing traffic, the firewall only checks the header of each packet for compliance with rules:

  • outgoing packets are only checked against outgoing rules;
  • incoming packets are only checked against incoming rules, even if the incoming packet is a response to an allowed outgoing request.

Ensure that basic firewall rules are not blocking port 22. For more information, see the Manage basic firewall rules guide.