Letting ssh remember your passwords

If you're like me, you ssh into the same small set of machines over and over. Maybe sometimes you run commands that sit on top of ssh, like scp for file copies. Wouldn't it be nice if you could have ssh remember your passwords? This is especially useful for automation.

It seems like this has been built into ssh forever, but I just discovered it. So, excuse me if this is child's play for the grey beards out there.

Create your public/private key pair. Hit enter at any prompts; you don't need a password.

          ssh-keygen -t rsa

You now have a local key in /home/$user/.ssh/id_rsa.pub

Copy your key to the remote machine (server1), and append it to /home/$user/.ssh/authorized_keys

          ssh $user@server1 mkdir -p ~/.ssh
          cat ~/.ssh/id_rsa.pub | ssh $user@server1 'cat >> ~/.ssh/authorized_keys'

That's it! You should now be able to ssh and scp to the remote machine without supplying a password.

Security note: It's important to note that ssh is not remembering a password, it's using a pre-exchanged public/private key. Regardless, you want to think twice about doing this in a production environment, where access to one terminal would result in accesses to many other terminals.

Edit: Most distributions will have a ssh-copy-id command, which makes the "cat" above obsolete.

I'm currently working at NerdWallet, a startup in San Francisco trying to bring clarity to all of life's financial decisions. We're hiring like crazy. Hit me up on Twitter, I would love to talk.

Follow @chase_seibert on Twitter