ssh-agent: Could not open a connection to your authentication agent

14,583

First Choice: Don't Use sudo

ssh-add .ssh/bitbucket_ssh

Second Choice: Pass The Environment Variable Explicitly

Assuming your bitbucket_ssh file is only readable by root -- the more appropriate approach is to fix the permissions, but as an interim approach, you can pass SSH_AUTH_SOCK through:

sudo env SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add .ssh/bitbucket_ssh
Share:
14,583

Related videos on Youtube

Tsiruan
Author by

Tsiruan

Updated on June 04, 2022

Comments

  • Tsiruan
    Tsiruan almost 2 years

    I have done a ton of research already, but none of those works. This is output from my terminal:

    $ ps aux | grep ssh-agent
    tsiruan   4080  0.0  0.0  13468   388 ?        Ss   11:47   0:00 ssh-agent
    $ env | grep SSH
    SSH_AUTH_SOCK=/tmp/ssh-8CJH68abyLAa/agent.4079
    SSH_AGENT_PID=4080
    $ sudo ssh-add .ssh/bitbucket_ssh
    [sudo] password for tsiruan:
    Could not open a connection to your authentication agent.
    

    I have tried $ eval $(ssh-agent) with backticks, single quote, double quote, with and without parentheses, with and without -s option, and even some answers like:

    $ exec ssh-agent bash
    

    please help me , I am running bash on arch linux.

    • Charles Duffy
      Charles Duffy over 6 years
      StackOverflow is for questions about writing software. Consider Unix & Linux or SuperUser for questions about using tools that shipped with your system.
    • Charles Duffy
      Charles Duffy over 6 years
      that said, the big problem here is that you're using sudo to run ssh-add. When you run sudo, that makes your command run as a different user, with a different environment (so it no longer has your SSH_AUTH_SOCK). This is the same problem asked on Unix.SE here.
    • Charles Duffy
      Charles Duffy over 6 years
      BTW -- using sudo on commands where you shouldn't have to use sudo often creates permission problems that force you to use sudo again later (when you otherwise wouldn't need it). It's a tool that should only be used when you have a very specific reason to do so.
    • Tsiruan
      Tsiruan over 6 years
      Thank you for your detailed explanation!
  • Charles Duffy
    Charles Duffy over 6 years
    Community Wiki since this is answering a known-off-topic question.