How to supress ssh from prompting key passphrase for passwordless logins



Generating authentication key pairs

Use the ssh-keygen command to generate authentication key pairs as described below. Provide a passphrase, for example "password", when creating the key pairs.

# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/himanshu/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/himanshu/.ssh/id_rsa.
Your public key has been saved in /home/himanshu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4lYqkqgXmhIxoyMdT+ZfGFCxeMUqTnXLjrRQKjbEC/U root@funebslab
The key's randomart image is:
+---[RSA 2048]----+
| o.  .oo.        |
|. o...ooo        |
| o .E=o+ .       |
|+ * D.+ o        |
|.* @ +.*S        |
|o.               |
+----[SHA256]-----+

Copy the Public key to remote host
1. Copy the public key to ~/.ssh/authorized_keys on the remote system.


 
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.56.71

2. Now try logging into the machine, with "ssh ‘root@192.168.56.71′", and check in the .ssh/authorized_keys file to make sure we haven’t added extra keys that you weren’t expecting.

$ ssh 192.168.56.71
Enter passphrase for key '/home/himanshu/.ssh/id_rsa': 
Last login: Sun Aug 01 09:03:50 2021 from 192.168.56.71


Add private key password to ssh-agent

1. To add the private key password to ssh-agent, enter the following command:

$ exec ssh-agent $SHELL
2. The next step is to use the ssh-add command to add the key.

$ ssh-add
Enter passphrase for /home/himanshu/.ssh/id_rsa: 
Identity added: /home/himanshu/.ssh/id_rsa (/root/.ssh/id_rsa)
3. The "ssh-add -l" command lists fingerprints of all identities currently represented by the agent.

$ ssh-add -l
2048 SHA256:4lYqkqgXmhIxoyMdT+ZfGFCxeMUqTnXLjrRQKjbEC/U /root/.ssh/id_rsa (RSA)

4.Login in to the remote system without password now.

$ ssh 192.168.56.71
Last login: Sun Aug 01 09:03:50 2021 from 192.168.56.71

Note: The passphrase is remembered for only the current login session and is forgotten when you log out.




If you like please follow and comment