• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to avoid ssh from prompting key passphrase for passwordless logins

by admin

The ssh-agent program is an authentication agent that handles passwords for SSH private keys. Use ssh-add to add the keys to the list maintained by ssh-agent. After you add a private key password to ssh-agent, you do not need to enter it each time you connect to a remote host with your public key.

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 (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4lYqkqgXmhIxoyMdT+ZfGFCxeMUqTnXLjrRQKjbEC/U root@geeklab
The key's randomart image is:
+---[RSA 2048]----+
| o.  .oo.        |
|. o...ooo        |
| o .E=o+ .       |
|+ * B.+ o        |
|.* @ +.*S        |
|=.o.+.++o        |
|o=o...+.         |
|= .. o.          |
|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.12.10

2. Now try logging into the machine, with “ssh ‘root@192.168.12.10′”, 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.12.10
Enter passphrase for key '/root/.ssh/id_rsa': 
Last login: Wed Apr 06 09:03:50 2014 from 192.168.12.20

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 /root/.ssh/id_rsa: 
Identity added: /root/.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. You can try loggin in to the remote system without password now.

$ ssh 192.168.12.10
Last login: Thu Apr 06 11:13:29 2014 from 192.168.12.20

In this example, the passphrase is remembered for only the current login session and is forgotten when you log out.

Filed Under: Linux

Some more articles you might also be interested in …

  1. lvcreate Command Examples in Linux
  2. pvs Command Examples in Linux
  3. How to use fdisk to partition a disk in Linux
  4. How To Create a Local Yum Repository for MySQL Enterprise Packages
  5. date Command Examples in Linux
  6. Bash for loop Examples
  7. TCP Wrapper (hosts.allow & hosts.deny) Command Options in Linux
  8. Linux OS Service ‘nfslock’
  9. How to configure interface in “Promiscuous Mode” in CentOS/RHEL
  10. jq: command not found (JSON CLI Parser)

You May Also Like

Primary Sidebar

Recent Posts

  • qemu-system-x86_64: command not found
  • timedatectl: command not found
  • mpirun.openmpi: command not found
  • startkde: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright