Rambling Labs Blog Ramblings on software development

  • Set up ssh public/private key for no password prompts

    It's been a while since my last post. I've had a busy couple of weeks. But here I am again :).

    Last week, I was setting myself up for a couple of features that I have to add to a project. I had ssh access (which is a good thing), but I was getting tired of typing in my password each and everytime I tried to connect to the server. The solution to this is fairly simple.

    • First, be sure to have your public ssh key in hand or generate your own with:
    ssh-keygen -t rsa -C youremail@yourdomain.com
    

    Be sure to generate it with no passphrase (remember that our goal is never get prompted when connecting through ssh).

    • Then, on the server, make sure that there's a file called authorized_keys in the ~/.ssh directory. If it doesn't exist, create it.
    • Add a new line to that file with the contents of your public key file (id_rsa.pub if you left it with the default name).
    • Also on the server, make sure that the files and directories have this set of permissions (you can just execute the following commands):
    chmod 644 ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    chmod 755 ~
    
    • Finally, test it out login in with ssh from a new prompt.

    That's it!
    No more password prompts! :D

  • blog comments powered by Disqus