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:
  2.  
  3. Create a public ssh key, if you haven't one already.
  4. Look at ~/.ssh. If you see a file named id_dsa.pub 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.
  6.  
  7. Make sure your .ssh dir is 700:
  8. chmod 700 ~/.ssh
  9.  
  10. Get your public ssh key on the server you want to login automatically.
  11. A simple scp ~/.ssh/id_dsa.pub [email protected]: is ok.
  12.  
  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 id_dsa.pub >> .ssh/authorized_keys while at your home directory.
  16.  
  17. Instead of steps 3 and 4, you can issue something like this:
  18. cat ~/.ssh/id_dsa.pub | ssh -l remoteuser remoteserver.com 'cat >> ~/.ssh/authorized_keys'
  19.  
  20. Remove your public key from the home directory on the server.
  21.  
  22. Done!
  23.  
  24. You can now login:
  25.  
  26. ssh -l remoteuser remoteserver.com or ssh remoteuser@remoteserver.com without getting asked for a password.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.