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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. Example of using getnstimeofday in Linux kernel
  2. gist: Upload code to https://gist.github.com
  3. How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  4. cpio Command Examples in Linux
  5. crontab Command Examples in Linux
  6. cp: omitting directory – error while copying a directory in Linux
  7. top Command Examples in Linux
  8. “az tag” Command Examples (Manage tags on a resource)
  9. 11 Useful “ssh” and “scp” Commands in Linux
  10. cmatrix: Shows a scrolling Matrix like screen in the terminal

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright