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 Products → Dedicated Servers → Servers → 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 Products → Dedicated Servers → Servers → server page → Operating System tab → IP.
Information about the SSH connection process and any occurring connection issues will appear in the response.
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/Information about the files in the
.sshdirectory 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_keysHere,
authorized_keysis a file containing public SSH keys that are 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 orauthorized_keysfile does not exist, or the requested public key is not in the file, place the SSH key on the server.
Configure access rights
On a dedicated server
On a local computer
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.
-
Check rights for the
~/.sshdirectory:ls -ld ~/.sshInformation about rights for the
~/.sshdirectory will appear in the response. For example:drwx------ 2 username username 4096 Oct 24 10:00 /home/user/.sshWhere:
-
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
usernamevalue — user with owner rights; -
the second
usernamevalue — user group. Usually the same as the username.
The rights for the
~/.sshdirectory correspond to the700code: read, create, and delete files in the directory, access to the directory. -
-
If the rights for the
~/.sshdirectory differ in step 3, set the correct rights:chmod 700 ~/.sshWhere:
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.
-
If the owner of the
~/.sshdirectory is incorrect, change it:sudo chown -R <username>:<user_group> ~/.sshSpecify:
<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 theid <username>command, where<username>is the username.
-
Check rights for the
~/.ssh/authorized_keysfile:ls -l ~/.ssh/authorized_keysInformation about rights for the
~/.ssh/authorized_keysfile will appear in the response. For example:-rw------- 1 username username 234 Oct 24 10:00 /home/username/.ssh/authorized_keysWhere:
-
-rw-— object type and the rights systems users have for it, where:-—~/.ssh/authorized_keysobject type: regular file;rw-— owner rights: read and write;---— no group rights;---— no rights for other system users;
-
the first
usernamevalue — user with owner rights; -
the second
usernamevalue — user group. Usually the same as the username.
The rights for the
~/.ssh/authorized_keysfile correspond to the600code: read and write. -
-
If rights for the
~/.ssh/authorized_keysfile differ in step 6, set the correct rights:sudo chmod 600 ~/.ssh/authorized_keysWhere:
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
-
Check the
sshdservice status:systemctl status sshdInformation about the
sshdservice status will appear in the response. 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 waiting for incoming connections on:ss -tlnp | grep sshdInformation about the ports that the
sshdservice 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,
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 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 Products → Dedicated Servers → Servers → 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 Products → Dedicated Servers → Servers → server page → Operating System → field IP.
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/0Here,
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22is a rule that allows connections to port22. -
If
iptablespolicies for port22are set toDROPorREJECT, 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 when connecting or if the server does not offer key authentication, check the SSH server settings.
-
Open the
/etc/ssh/sshd_configconfiguration file with thevitext editor:vi /etc/ssh/sshd_config -
Ensure that the configuration contains the following parameters:
PubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysWhere:
PubkeyAuthentication— when set toyes, this enables authentication using SSH keys;AuthorizedKeysFile— path to the file containing the public SSH key.
-
If the
PubkeyAuthenticationandAuthorizedKeysFileparameters are missing, add them. -
Exit the
vitext editor with your changes saved::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
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.