Tuesday, July 26, 2011

SSH without a password

To avoid entering your password every time you log in via ssh, add your public key to the .ssh/authorized_keys file in your home directory on the remote machine.

On the local machine:

  • Generate pair of keys:
    ssh-keygen
    and enter the name of the key (default is id_rsa), then hit enter twice (password prompts).
  • Append the public key (key_name.pub) to the list of keys on the remote machine:
    < cat ~/.ssh/key_name.pub | ssh user@remote_machine "cat >> ~/.ssh/authorized_keys"
  • Make sure that ~/.ssh/authorized_keys has the 600 permissions!
  • If you entered the name of the key different that default one (id_rsa) then you need to connect/copy with the -i option (ssh -i ~/.ssh/key_name or scp -i ~/.ssh/key_name)

No comments:

Post a Comment