I’ve been using a Mac now at work for just about all of my activities. We have a fair number of UNIX hosts that I need to work with and I’ve heard you can log in using SSH without passwords but have never been able to get it to work right. I’ve now found a solution!
Let’s set up a few basic parameters
- you = your account name on the servers
- yourserver = The machine you are logging in from. It’s most likely your laptop.
- remoteserver = The machine you are logging in to. It’s most likely the one that is not near by.
Setting your identity
For SSH to work correctly, you need to set up an identity the other server can trust. So, if you can log into your machine, the remote server trusts that the login credential of your machine is strong enough to have it not reprompt you for credentials. To do so, just run the following session on your computer.
you@yourserver:~> ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa): Created directory '/home/you/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/you/.ssh/id_rsa. Your public key has been saved in /home/you/.ssh/id_rsa.pub. The key fingerprint is: WX:YZ:WX:YZ:WX:YZ:WX:YZ:WX:YZ:WX:YZ:WX:YZ:WX:YZ you@yourserver
Establishing the Trust Relationship
For SSH to work you need to have your public key on the remote server so it knows that it is you making the login request. To do so:
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
you@yourserver:~> ssh you@remoteserver mkdir -p .ssh
Finally append your new public key to you@remoteserver:.ssh/authorized_keys and enter your password one more time:
you@yourserver:~> cat .ssh/id_rsa.pub | ssh you@remoteserver 'cat >> .ssh/authorized_keys'
From now on you can log into remoteserver as you without a password:
you@yourserver:~> ssh remoteserver you@remoteserver:~>