Add an SSH key to a server:

  • Copying the contents of your public SSH key on your local computer. You can use the following command to output the contents of the file:

cat ~/.ssh/
You should see output similar to the following:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyVGaw1PuEl98f4/7Kq3O9ZIvDw2OFOSXAFVqilSFNkHlefm1iMtPeqsIBp2t9cbGUf55xNDULz/bD/4BCV43yZ5lh0cUYuXALg9NI29ui7PEGReXjSpNwUD6ceN/78YOK41KAcecq+SS0bJ4b4amKZIJG3JWmDKljtv1dmSBCrTmEAQaOorxqGGBYmZS7NQumRe4lav5r6wOs8OACMANE1ejkeZsGFzJFNqvr5DuHdDL5FAudW23me3BDmrM9ifUzzjl1Jwku3bnRaCcjaxH8oTumt1a00mWci/1qUlaVFft085yvVq7KZbF2OPPbl+erDW91+EZ2FgEi+v1/CSJ5 your_username@hostname

  • Once you have copied that text, connect to your server via SSH with the user you would like to add your key to:

ssh your_username@
Create the ~/.ssh directory and authorized_keys file if they don’t already exist:

  • mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys
    Give the ~/.ssh directory and authorized_keys files appropriate file permissions:

chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
Open the authorized_keys file with the text editor of your choice (nano, for example). Then, paste the contents of your public key that you copied in step one on a new line at the end of the file.

Facebook Comments

You may also like