SSH Passwordless Login Using SSH Keygen in 5 Easy Steps
If you want to sent a secret message to remort mechine, the you need to know the remort mechine's public key after that you need to encrypt that message using the remort mechines's public key after that sent the message to remort mehine. After receiving the message the remort mechine decrypt the message with its private key.
In this example we will setup SSH password-less automatic login from server 192.168.56.1 as user anusree to 192.168.56.101 with user anusree.
step 1: Create Authentication SSH-Kegen Keys on – (192.168.56.1)
anusree@anusree-Inspiron-5547:~$
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/anusree/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/anusree/.ssh/id_rsa.
Your public key has been saved in /home/anusree/.ssh/id_rsa.pub.
The key fingerprint is:
b2:d4:46:24:c9:06:62:f4:f1:d7:0a:ad:4f:37:40:c5
anusree@anusree-Inspiron-5547
The key's randomart image is:
+--[ RSA 2048]----+
| .+ oo..oo. |
| . o o+= .E |
| ..o = . |
| * o |
| + S o |
| . * . . |
| . . |
| |
| |
+-----------------+
First login into server 192.168.56.1 with user anusree and generate a pair of public keys using following command.
This will create the public key and also privet key, public key is save in /home/anusree/.ssh/id_rsa.pub, and private key is saved in /home/anusree/.ssh/id_rsa.
Step 2: Create .ssh Directory on – 192.168.56.101 ------------> Use SSH from server 192.168.56.1 to connect server 192.168.56.101 using anusree as user and create .ssh directory under it, using following command.
anusree@anusree-Inspiron-5547:~$
ssh anusree@192.168.56.101 mkdir -p .ssh
anusree@192.168.56.101's password: [Enter Your Password Here]
step 3: Upload Generated Public Keys to – 192.168.56.101 -----------> Use SSH from server 192.168.56.1 and upload new generated public key (id_rsa.pub) on server 192.168.56.101 under anusree‘s .ssh directory as a file name authorized_keys.
anusree@anusree-Inspiron-5547:~$
cat .ssh/id_rsa.pub | ssh anusree@192.168.56.101 'cat >> .ssh/authorized_keys'
anusree@192.168.56.101's password: [Enter Your Password Here]
Step 4: Set Permissions on – 192.168.56.101 ---------> (optional)
Due to different SSH versions on servers, we need to set permissions on .ssh directory and authorized_keys file.
anusree@anusree-Inspiron-5547:~$
ssh anusree@192.168.56.11 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
sheena@192.168.0.11's password: [Enter Your Password Here]
Step 5: Login from 192.168.0.12 to 192.168.0.11 Server without Password
From now onwards you can log into 192.168.56.101 as anusree user from server 192.168.56.1 as anusree user without password.
anusree@anusree-Inspiron-5547:~$
ssh anusree@192.168.56.101
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Wed Apr 22 00:09:10 2015 from 192.168.56.1