If you’re new to using SSH keys and encounter problems connecting to your servers, it’s often due to formatting errors or assigning an already existing key to a system user.

Troubleshooting SSH Key Issues

Incorrect Formatting

The primary issues with SSH keys not working often involve incorrect formatting. The two most common issues we see are:

  1. Broken Lines: The key is fragmented over multiple lines instead of being a single continuous line.
  2. Missing Prefix: The key lacks “ssh-rsa” at the beginning.

Here’s an example of incorrect formatting:

ssh-rsa
AAAAB3NzaC1yc2EAAAABJQAAAQEAxznqQ5ic/ctZi1AKS6ysTYo+v3fsADTLup
HqvvtgK0WfFtFYEvdAKjIz1abMXH5srFs6mqDJ56jxtxc9alBnINanKsnYmEzP
3cdcJTREA/BUoShSonXNL3pJs8dtJovldejw6QPB2S2Wnt4FfFOHidwilN15xb
K3PrPqdGyqrmvMkqXRRABfosAzhdLa9t26P9lhcKhEIWmeQipWgjVyNPkkEraa
7HkIPC04t8rjuMtBtHkZ0iv6SqU14d7pODcVR6/nPzm2SqTpDJ8LV8kx1v0ZHo
1k2XYHd6jCB38ns0kjVbPPmFhwUDoLaZa6esKAnJ+SnAc3JExL7Mw1ZtfEjQ==
rsa-key-20200519

Here’s the correct formatting example:

ssh-rsa AAAAB3NzaC1yc2hhHYT%^reAGuYlop;xznqQ5ic/ctZi1AKS6ysTYo+v3fsADTLupHqvvtgK0WfFtFYEvdAKjIz1abMXH5srFs6mqDJ56jxtxc9alBnINanKhoifeoihfqoihsnYmEzP3cdcJTREA/BUoShSonXNL3pJs8dtJovldejw6QPB2S2Wnt4FfFOHidwilN15xbK3PrPqdGyqrmvMkqXRRABfosAzhdLa9t26P9lhcKhEIWmeQipWgjVyNPkkEraa7HkIPC04t8rjuMtBtHkZ0iv6SqU14d7pODcVR6/nPzm2SqTpDJ8LV8kx1v0ZHo1k2XYHd6jCB38ns0kjVbPPmFhwUDoLaZa6esKAnJ+SnAc3JExL7Mw1ZtfEjQ== rsa-key-20200519

Ensure there’s a space between “ssh-rsa” and the key itself.

Key Already Assigned

Another reason for failure could be assigning the same key to a system user previously. If that’s the case, you cannot push the same key to a server more than once.

In such a scenario, the easiest resolution is to create a new SSH key. Avoid reusing keys already associated with a system user to ensure smooth operations.