SSH — Configure key-based authentication

One of my favorite things to do when managing Linux systems is to configure key-based authentication. This allows me to connect to multiple systems via scripts without have to re-authenticate every time. A decent walkthrough is available at
Scenario: You are user A on host A, and you want to log onto host B as user B

  1. As user A on host A, execute
    1. ssh-keygen -t rsa
  2. Echo out the contents of ~/.ssh/ (save to clipboard or copy via ssh to host B)
  3. As user B on host b, make the .ssh directory if it doesnt already exist
    1. mkdir ~/.ssh
  4. Edit the file ~/.ssh/authorized_keys and enter the contents from

Your now done. Assuming all went well, user A on host A should be able to run ssh b@b and be automatically logged in

3 thoughts on “SSH — Configure key-based authentication

  • March 17, 2011 at 1:30 pm


    I think you forgot to set the permissions on both the directory .ssh and the file authorized_keys:

    .ssh must be 700
    .ssh/authorized_keys must be 644

    Otherwise you may be unable to log in using the exchanged key.

    You should also use the dsa format for the key, it's more secure.

    Best Regards,
    Alberto M.

  • May 27, 2011 at 6:15 pm

    you can just use ssh-copy-id to install your public key to a remote machine

Leave a Reply