Could not open a connection to your authentication agent

Posted: June 7, 2010 in Administration, Cygwin, Security, Tricks, Troubleshooting
Tags: , , , , , , ,

In order to make the connections to several servers through SSH easier, I use public/private keys-based authentication.

Cygwin provides all the basic tools related to SSH : ssh client, ssh-keygen, ssh-copy-id, ssh-add and ssh-agent.

Once I created my DSA keys with a passphrase, I sent my public key to all the involved servers with the ssh-copy-id utility.  So, each time I connect to a server, I only have to type my passphrase. It is possible to avoid it by using ssh-agent.

To start it : exec ssh-agent /usr/bin/bash

If you do not use exec, you will get the following error message :

Could not open a connection to your authentication agent

To add your DSA identity to your authentication agent : ssh-add ~/.ssh/id_dsa

Type your passphrase once and then, you will not need to type it anymore. You will be able to connect to servers where you have uploaded your public key.

This solution works only for your current xterm. If you open a new xterm session, you will have to type your passphrase.

  1. […] Here is the original post:  Could not open a connection to your authentication agent … […]

  2. Steve says:

    How would I add this to my bash profile to run when I connect?

    • For instance, you can put the following line in your bash profile :

      alias add=’/usr/bin/ssh-add’

      Open a new terminal and type add. It will ask for the passphrase related to your private key and you won’t need to type it again.

  3. Ahh yes. This will help me immensely.

    Do you need to type the passphrase each time?

  4. dhanunjay says:

    could u please help how to resolve this in windows environment

  5. keo says:

    How I can run this at open cygwin?

    I try adding to my .bashrc the following:

    echo ‘hello world 1’
    ssh-agent /usr/bin/bash
    echo ‘hello world 2’
    ssh-add.exe /home/dev/.ssh/key_alfredo
    echo ‘hello world 3’

    seems it starts a infinite loop printing “hello world 1” and no executes the other commands.

    any suggestions?

  6. keo says:

    I found this script helper here:

    and then completed with a line and everything works fine :)

    hope this helps anyone

    export SSH_AUTH_SOCK=/home/dev/.ssh-socket

    ssh-add -l >/dev/null 2>&1
    if [ $? = 2 ]; then
    # No ssh-agent running
    rm -rf $SSH_AUTH_SOCK
    ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
    source /tmp/.ssh-script
    echo $SSH_AGENT_PID > /home/dev/.ssh-agent-pid
    rm /tmp/.ssh-script

    ssh-add.exe /home/dev/.ssh/key_alfredo&>shell.log

  7. Dave says:

    If this doesn’t work,

    exec ssh-agent /usr/bin/bash

    this worked for me:

    eval $(ssh-agent)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s