Password-less SSH

SSH between two machines without password. Easy?

Yes, I’ll show you how.

What do we use password-less SSH for? A secure encrypted channel between two machines. Now when we want to have a permanent secure channel between these two machines, without entering password everytime we need to access, best way is to make them password-less.

How does this work? The concept of Public-private keys. We generate the RSA key pair for our SSH, and provide our public key to the next machine. Its that easy. The next machine need to add our public keys to their file called authorized keys. Done.

Steps are here –

Generate the ssh keys first for starting the ssh service on both sides. And then start the ssh service.

sshd-generate

# /etc/init.d/ssh start

You can check the ssh service running on port 22 by the netstat command.

Next is to generate our RSA keypair. The command is,

ssh-keygen

keygen

We have our public and private keys with us. Now let’s send the public key to the remote machine, using Secure Copy. The keys in our machine are stored at /root/.ssh/

# scp /root/.ssh/id_rsa.pub 192.168.111.143:/root/.ssh/authorized_keys

(Replace your next machine’s IP with my 192.168.111.143)

keys sent

The authorized key set for the next machine is stored at /root/.ssh/authorized_keys

After the above command, you’ll be asked to enter the password. But that will be the last time someone asks for the ssh password. For secure shell from the next machine to yours, follow the same process from the next machine. That’s all folks!

Advertisements