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
Related videos on Youtube
Author by
Tsiruan
Updated on June 04, 2022Comments
-
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 over 6 yearsStackOverflow is for questions about writing software. Consider Unix & Linux or SuperUser for questions about using tools that shipped with your system.
-
Charles Duffy over 6 yearsthat said, the big problem here is that you're using
sudo
to runssh-add
. When you runsudo
, that makes your command run as a different user, with a different environment (so it no longer has yourSSH_AUTH_SOCK
). This is the same problem asked on Unix.SE here. -
Charles Duffy over 6 yearsBTW -- using
sudo
on commands where you shouldn't have to usesudo
often creates permission problems that force you to usesudo
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 over 6 yearsThank you for your detailed explanation!
-
-
Charles Duffy over 6 yearsCommunity Wiki since this is answering a known-off-topic question.