1

I m trying to save ssh authentication with the command ssh-add for sudo usage:

linux$ sudo ssh-add /root/.ssh/id_rsa
Could not open a connection to your authentication agent.

but as indicated it returns error

I made some research and I found that I have to to execute the command eval "ssh-agent -s" as indicated in the following link: https://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent/17695338#17695338

But I got error if execute it with sudo command

$ sudo eval `ssh-agent -s`
sudo: eval: command not found

What I m missing?

1
  • 1
    what are you trying to achieve? Why do you use sudo?
    – Jakuje
    Commented Jan 21, 2016 at 8:38

1 Answer 1

1

From the following link:

Fortunately, there is a way to solve this problem. Sudo has a configuration option that allows to keep given environmental variables from the user issuing the sudo command. The options is called env_keep and can be configured by changing the settings in /etc/sudoers files as follows (always use visudo to edit the file):

visudo

Defaults    env_reset
Defaults>root    env_keep+=SSH_AUTH_SOCK

In other words, add the line keeping the SSH_AUTH_SOCK variable below the Defaults env_reset line. Then save the file and run

ssh-agent bash
ssh-add

and you should be able to execute a sudo command that accesses your server using the non-sudo user’s key without being asked for the key passphrase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .