How to connect to an OpenSSH server without a passphrase in Linux

Home > Search > How-to
  by

Ssh-agent is a program that contains private keys and passphrases used to connect to an SSH server. Without ssh-agent, when making a connection to an SSH server using a public / private key pair, there will be a prompt to enter the passphrase associated with the public / private key pair.

Enter passphrase for key '/root/.ssh/id_dsa':

 

The ssh-agent command without any options will display basic information about the ssh-agent deamon, such as the socket and PID being used by ssh-agent. In this example, the socket is 30025 and the PID is 30026.

[root@server1 ~]# ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-fXi6UEtKUojG/agent.30025; export SSH_AUTH_SOCK;
SSH_AGENT_PID=30026; export SSH_AGENT_PID;
echo Agent pid 30026

 

The ssh-add command can be used to add your passphrase to ssh-agent. Before using ssh-add, you will want to start the ssh-agent.

[root@server1 ~]# eval `ssh-agent -s`
Agent pid 2023

 

Now add your passphrase.

[root@server1 ~]# ssh-add
Enter passphrase for /root/.ssh/id_rsa:

 

After you enter the correct passphrase, Identity added will be displayed.

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

 

Now when connecting to the SSH server, there will be no prompt to enter the passphrase associated with the public / private key pair.

[root@server1 ~]# ssh root@server2
Last login: Sun Jan 29 12:53:23 2017 from 192.168.0.141

 

It is important to note that your passphrase will not be permanently associated with the public / private key pair via ssh-agent. If you log out of the shell, reset the environment, or restart the machine, you will need to use ssh-add again to add your passphrase to ssh-agent. If you frequently connect to an SSH server, it would be preferrable to make this permanent via your BASH profile.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments