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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. How to change the path of the auditd log file /var/log/audit/audit.log
  2. How to change the interface name in CentOS/RHEL 8 using prefixdevname
  3. How to change a system’s machine-ID in Oracle Enterprise Linux 7
  4. How to configure EPEL repository in OEL 7
  5. Beginners guide to Device Mapper (DM) multipathing
  6. CentOS / RHEL : How to migrate storage (LVM) with pvmove Command
  7. CentOS / RHEL 6,7 : How to enable or disable XDMCP service (GDM)
  8. How to use “yum downloadonly” to download a package without installing it
  9. Linux Command line Basics – Executing commands from the command line
  10. CentOS / RHEL 7 : Understanding Kexec and Kdump

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary