Before upgrade

When I was running git clone git@... (using ssh) once per computer restart a window dialog appeared containing a textbox for inserting my SSH passphrase and confirmed with OK. Then the passphrase was no longer required until the next start of my system.

After upgrading to 13.10

After upgrading to Ubuntu 13.10 that window doesn't appear anymore but a message in terminal appears:

Enter passphrase for key '/home/username/.ssh/id_rsa': 

...every time when cloning a git repository this appears.

How can I fix this? I want to enter my passphrase only once.

  • 1
    I think you have to use the ssh-add command for that. Have you tried it? – devius Oct 20 '13 at 12:24
  • 2
    I tried ssh-agent bash + ssh-add. That works only for few minutes. – Ionică Bizău Oct 20 '13 at 12:27
  • I'm having the same problem after all. I think it may be a conflict between OpenSSH's ssh-agent and the Gnome Keyring Daemon. – devius Nov 8 '13 at 11:51
  • 1
  • 2
    Add AddKeysToAgent yes to .ssh/config works for me. – xslittlegrass Jan 2 '17 at 20:11
up vote 120 down vote accepted

Update: seems to be a bug from 13.10:

https://bugs.launchpad.net/ubuntu/+source/libpam-ssh/+bug/1247169


Anyway running the following commands the problem was fixed for me:

How to fix

I fixed this by entering the following commands:

$ ssh-agent bash

This creates a new bash process that allows you to add private keys. When adding a new private key you will be prompted for the passphrase once and only once.

And then:

$ ssh-add /home/username/.ssh/id_rsa
Enter passphrase for /home/username/.ssh/id_rsa: 
Identity added: /home/username/.ssh/id_rsa (/home/username/.ssh/id_rsa)

...where username is your username. You can do the same using $USER variable:

$ ssh-add /home/$USER/.ssh/id_rsa

Alternatively, just use ~ for your home directory.

$ ssh-add ~/.ssh/id_rsa

And the problem was fixed.

  • 41
    This doesn't solve the problem at all. It only adds the identity to the agent until you exit out of the terminal. If you open a new terminal you have to ssh-add again. – devius Nov 11 '13 at 12:15
  • @devius Yes, seems to be a bug. But, the commands above fixed my problem... – Ionică Bizău Nov 11 '13 at 13:57
  • 3
    So to clarify: With this "fix" you will only not have to type in the passphrase in that terminal again. The moment you open a new terminal - you will have to give the passphrase again. – harijay Feb 6 '14 at 15:33
  • 7
    I tried $ ssh-add /home/username/.ssh/id_rsa (without ssh-agent bash) and it worked for me even after reopening the terminal. But the complete solution for me was this one stackoverflow.com/a/4246809/532252. Everything is ok even after rebooting the machine. – kishie Feb 19 '14 at 7:49
  • 1
    I just typed ssh-add in the terminal. No need to switch to ssh-agent bash or specify an id_rsa file – henry74 Apr 10 '14 at 19:27

This Atlassian document fixed the issue for me on Ubuntu 14.04 Server Edition:

Just add this values into your .bashrc file:

SSH_ENV=$HOME/.ssh/environment

# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

And after logging in, it asks for password only once and it caches. You don't need to enter it each time.

  • 2
    This seems to work on other distros, like I just successfully used this answer on Sabayon Linux. – BH2017 Nov 20 '15 at 5:08
  • 1
    Thanks! This solution worked for me on an ubuntu system where the gnome-keyring-daemon didn't work because of dbus-daemon issues. Specifically, I was getting these errors "** Message: couldn't connect to dbus session bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11" and after setting the display environment variable I got "** Message: couldn't connect to dbus session bus: //bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed." – user207863 Feb 26 '16 at 17:05
  • 1
    This needs more upvotes, fixes the problem on virtualized Ubuntu 16.04 fine. – Niels Keurentjes Jul 31 '16 at 21:35
  • 2
    This fixes the problem for me on Bash for Windows as well. I tried launching Bash multiple times and it remembered the passphrase. Haven't tried a restart yet. – Amr Nov 27 '16 at 4:53
  • 2
    after trying all the other solutions, this worked for me. This should be the solution to the OP – João Pimentel Ferreira Aug 14 '17 at 19:23

0) Short answer

Add in your .ssh/config one line at the beginning:

AddKeysToAgent yes

and run git/ssh/... If it's not enough, check your ssh version and check that ssh-agent is loaded with these instructions:

1) Check the openssh version

Firstly check that your ssh version, it must be greater of equal to 7.2:

ssh -V

2) Edit the config file

If it's the case just add in your .ssh/config one line at the beginning:

AddKeysToAgent yes

3) Check if ssh-agent is already open

Usually distributions automatically load an ssh-agent. To check it, run

ps aux | grep -v grep | grep ssh-agent

If you don't see any line containing it, you need to load it by running:

eval $(ssh-agent)

Note that this enable the agent only on the current terminal, so to enable it everywhere, you can try to add this line in your ~/.profile file and reboot.

  • 7
    AddKeysToAgent yes is the canonical post-2016 answer – and exactly what most modern users are grepping about for. It's mid-2017. Ubuntu >= 16.04 (Xenial Xerus) is now a reasonable assumption. Most OpenSSH installations in the wild now support this option. Ad-hoc shell script kludges of the sort advocated by every other answer to this question are so... passé. </sigh> – Cecil Curry Aug 16 '17 at 4:16

A workaround for this bug is to add the following to the bottom of ~/.bashrc

eval `gnome-keyring-daemon --start`
  • 2
    Shouldn't gnome keyring just be part of your session? – Pavel Šimerda Nov 30 '14 at 15:09
  • 1
    If you are talking about 'should', then This question shouldn't be here on first place, if everything is that perfect – Anwar May 8 '16 at 17:35
  • 1
    Not sure if this belongs to .bashrc. Looks like you have to add it into some DE profile file – Dmitry Ginzburg Nov 7 '16 at 7:48

Users of the fish shell can use this script to do the same thing.

# content has to be in .config/fish/config.fish
# if it does not exist, create the file
setenv SSH_ENV $HOME/.ssh/environment

function start_agent                                                                                                                                                                    
    echo "Initializing new SSH agent ..."
    ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
    echo "succeeded"
    chmod 600 $SSH_ENV 
    . $SSH_ENV > /dev/null
    ssh-add
end

function test_identities                                                                                                                                                                
    ssh-add -l | grep "The agent has no identities" > /dev/null
    if [ $status -eq 0 ]
        ssh-add
        if [ $status -eq 2 ]
            start_agent
        end
    end
end

if [ -n "$SSH_AGENT_PID" ] 
    ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
    if [ $status -eq 0 ]
        test_identities
    end  
else
    if [ -f $SSH_ENV ]
        . $SSH_ENV > /dev/null
    end  
    ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null
    if [ $status -eq 0 ]
        test_identities
    else 
        start_agent
    end  
end

I use this:

vim ~/.profile

eval `/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg`
export SSH_AUTH_SOCK
export GPG_AGENT_INFO

If you use azure .ppk file

Just convert it to pem and add permission 400 with simple steps:

sudo apt-get install putty
puttygen <path_to_key>/keyname.ppk -O private-openssh -o <path>/aws_key.pem
sudo chmod 400 <path>/aws_key.pem
ssh -vi aws_key.pem ubuntu@<ip_address>

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.