SSH Connection Errors
If you encounter issues connecting to the server, run a diagnostic. After the diagnostic, you can resolve some frequently occurring errors on your own.
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— flag to enable debug mode, which allows you to trace the entire SSH connection establishment process;<username>— username (login). You can find it in the Control panel: in the top menu, click Products → Dedicated Servers → Servers → server page → Operating system tab → Login field;<ip_address>— public IP address of the server. You can find it in the Control panel: in the top menu, click Products → Dedicated Servers → Servers → server page → Operating system tab → IP field.
The response will show information about the SSH connection establishment process and occurring connection issues.
Connection issues
Check for the SSH key file
Check the public key on the server
Check the private key on the local computer
-
Check for the
.sshdirectory and theauthorized_keysfile:ls -la ~/.ssh/The response will show information about files in the
.sshdirectory. 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_keysWhere
authorized_keysis a file containing public SSH keys allowed to connect to the server. -
Display the contents of the
authorized_keysfile:cat ~/.ssh/authorized_keysOne or more public SSH keys will appear in the response. For example:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP... user@examplessh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC... admin@exampleEnsure that the SSH key corresponds to the private key used on the client.
-
If the
.sshdirectory or theauthorized_keysfile does not exist, or the file does not contain the required public key, place the SSH key on the server.
Configure access rights
On a dedicated server
On a local computer
The SSH server strictly checks user permissions for the ~/.ssh directory and the ~/.ssh/authorized_keys file. If the permissions are too permissive, the SSH connection cannot use the keys even if they are specified correctly.
-
Check permissions for the
~/.sshdirectory:ls -ld ~/.sshThe response will show information about permissions for the
~/.sshdirectory. For example:drwx------ 2 username username 4096 Oct 24 10:00 /home/user/.sshWhere:
-
drwx------— object type and its permissions for system users, where:d— object type: directory;rwx— owner permissions: reading, creating, and deleting files in the directory, accessing the directory;---— no permissions for the group. Group members cannot read, write, or enter the directory;---— no permissions for other system users;
-
the first
usernamevalue — user with owner permissions; -
the second
usernamevalue — user group. Usually identical to the username.
Permissions for the
~/.sshdirectory correspond to code700: reading, creating, and deleting files in the directory, accessing the directory. -
-
If the permissions for the
~/.sshdirectory differ in step 3, set the correct permissions:chmod 700 ~/.sshWhere:
7— owner permissions: reading, creating, and deleting files in the directory, accessing the directory;0— no permissions for the group;0— no permissions for other system users.
If successful, the command will not display any output.
-
If the owner of the
~/.sshdirectory is incorrect, change it:sudo chown -R <username>:<user_group> ~/.sshSpecify:
<username>— username under which you connect to the server via SSH;<user_group>— user group, usually identical to the username. You can check it using the commandid <username>, where<username>is the username.
-
Check permissions for the
~/.ssh/authorized_keysfile:ls -l ~/.ssh/authorized_keysThe response will show information about permissions for the
~/.ssh/authorized_keysfile. For example:-rw------- 1 username username 234 Oct 24 10:00 /home/username/.ssh/authorized_keysWhere:
-
-rw-------— object type and its permissions for system users, where:-— object type for~/.ssh/authorized_keys: regular file;rw-— owner permissions: reading and writing;---— no permissions for the group;---— no permissions for other system users;
-
the first
usernamevalue — user with owner permissions; -
the second
usernamevalue — user group. Usually identical to the username.
Permissions for the
~/.ssh/authorized_keysfile correspond to code600: reading and writing. -
-
If the permissions for the
~/.ssh/authorized_keysfile differ in step 6, set the correct permissions:sudo chmod 600 ~/.ssh/authorized_keysWhere:
6— owner permissions: reading and writing;0— no permissions for the group;0— no permissions for other system users.
If successful, the command will not display any output.
Check SSH service status
-
Check the status of the
sshdservice:systemctl status sshdThe response will show information about the status of the
sshdservice. For example:Active: active (running) -
If the
sshdservice is stopped, restart it:systemctl start sshd
Check SSH port
By default, the SSH server accepts connections on port 22.
-
Check which ports the
sshdservice is listening on for incoming connections:ss -tlnp | grep sshdThe response will show information about the ports on which the
sshdservice accepts connections. 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))Where
22is the port on which the SSH server accepts connections.If the output is empty, the
sshdservice is not running or is not accepting connections. -
Check which port is specified in the SSH configuration:
sshd -T | grep ^portInformation about the SSH server ports will appear in the response. For example:
port 2222 -
If the SSH ports in steps 3 and 4 do not match, restart the
sshdservice:systemctl restart sshd -
If the SSH port has been changed on the server, 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 find it in the Control panel: in the top menu, click Products → Dedicated Servers → Servers → server page → Operating system tab → Login field;<ip_address>— public IP address of the server. You can find it in the Control panel: in the top menu, click Products → Dedicated Servers → Servers → server page → Operating system tab → IP field.
Check firewall settings
Ensure that incoming connections to the SSH port are allowed by firewall rules.
-
For diagnostics, temporarily turn off the firewall and test the connection:
3.1. Turn off the firewall:
systemctl stop firewalld3.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 -
Check
iptablesrules:iptables -L -n -vA 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 destination145 8700 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2280 4800 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0Where
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22is a rule allowing connections to port22. -
If
DROPorREJECTpolicies are set in theiptablesrules for port22, change the firewall configuration to allow incoming connections to port22. -
Try connecting via SSH again.
Check SSH configuration on the server
If a Permission denied (publickey) error occurs upon connection or the server does not offer key authentication, check the SSH server settings.
-
Open the configuration file
/etc/ssh/sshd_configwith the text editorvi:vi /etc/ssh/sshd_config -
Ensure that the configuration contains the following parameters:
PubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysWhere:
PubkeyAuthentication— when set toyes, allows authentication using SSH keys;AuthorizedKeysFile— path to the file with the public SSH key.
-
If the parameters
PubkeyAuthenticationandAuthorizedKeysFileare missing, add them. -
Exit the text editor
viwhile saving changes::wq -
Optional: if you added parameters to the configuration file in step 5, check it for errors:
sshd -tIf the output is empty, the configuration is correct.
-
If you added parameters to the configuration file in step 5, restart the SSH service:
systemctl restart sshd
Check basic firewall rules
Basic firewall processes each packet in isolation — it does not remember established connections and does not track the state of TCP sessions. When analyzing traffic, the firewall only checks the header of each packet for compliance with the 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.
Make sure that the basic firewall rules do not block port 22. Learn more in the Manage basic firewall rules instructions.