Automatic SSH login

/ Published in: Bash
Save to your folder(s)

How to automatically login with SSH. Also known as “key-based authorization with SSH” or simply “publickey authorization”.

Copy this code and paste it in your HTML
  1. Here are the steps:
  3. Create a public ssh key, if you haven't one already.
  4. Look at ~/.ssh. If you see a file named then you obviously already have a public key. If not, simply create one. ssh-keygen -t dsa should do the trick.
  5. Please note that there are other types of keys, e.g. RSA instead of DSA. I simply recomend DSA, but keep that in mind if you run into errors.
  7. Make sure your .ssh dir is 700:
  8. chmod 700 ~/.ssh
  10. Get your public ssh key on the server you want to login automatically.
  11. A simple scp ~/.ssh/ [email protected]: is ok.
  13. Append the contents of your public key to the ~/.ssh/authorized_keys and remove it.
  14. Important: This must be done on the server you just copied your public key to. Otherwise you wouldn't have had to copy it on your server.
  15. Simply issue something like cat >> .ssh/authorized_keys while at your home directory.
  17. Instead of steps 3 and 4, you can issue something like this:
  18. cat ~/.ssh/ | ssh -l remoteuser 'cat >> ~/.ssh/authorized_keys'
  20. Remove your public key from the home directory on the server.
  22. Done!
  24. You can now login:
  26. ssh -l remoteuser or ssh without getting asked for a password.

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.