Did You Start ssh-agent
?
You might need to start ssh-agent
before you run the ssh-add
command:
eval `ssh-agent -s`
ssh-add
Note that this will start the agent for msysgit Bash on Windows. If you’re using a different shell or operating system, you might need to use a variant of the command, such as those listed in the other answers.
See the following answers:
- ssh-add complains: Could not open a connection to your authentication agent
- Git push requires username and password (contains detailed instructions on how to use ssh-agent)
- How to run (git/ssh) authentication agent?.
- Could not open a connection to your authentication agent
To automatically start ssh-agent and allow a single instance to work in multiple console windows, see Start ssh-agent on login.
Why do we need to use eval
instead of just ssh-agent
?
SSH needs two things in order to use ssh-agent: an ssh-agent instance running in the background, and an environment variable set that tells SSH which socket it should use to connect to the agent (SSH_AUTH_SOCK IIRC). If you just run ssh-agent then the agent will start, but SSH will have no idea where to find it.
from this comment.
Public vs Private Keys
Also, whenever I use ssh-add
, I always add private keys to it. The file ~/.ssh/id_rsa.pub
looks like a public key, I’m not sure if that will work. Do you have a ~/.ssh/id_rsa
file? If you open it in a text editor, does it say it’s a private key?
Connor
3,9262 gold badges27 silver badges40 bronze badges
answered Jul 25, 2013 at 3:37
24
The following command worked for me. I am using CentOS.
exec ssh-agent bash
answered Dec 5, 2013 at 15:10
mianjeemianjee
3,2471 gold badge11 silver badges2 bronze badges
8
Could not open a connection to your authentication agent
To resolve this error:
bash:
$ eval `ssh-agent -s`
tcsh:
$ eval `ssh-agent -c`
Then use ssh-add
as you normally would.
Hot Tip:
I was always forgetting what to type for the above ssh-agent commands, so I created an alias in my .bashrc
file like this:
alias ssh-agent-cyg='eval `ssh-agent -s`'
Now instead of using ssh-agent
, I can use ssh-agent-cyg
E.g.
$ ssh-agent-cyg
SSH_AUTH_SOCK=/tmp/ssh-n16KsxjuTMiM/agent.32394; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32395; export SSH_AGENT_PID;
echo Agent pid 32395;
$ ssh-add ~/.ssh/my_pk
Original Source of fix:
http://cygwin.com/ml/cygwin/2011-10/msg00313.html
answered Jul 17, 2013 at 8:54
Chris SnowChris Snow
23k33 gold badges136 silver badges297 bronze badges
5
MsysGit or Cygwin
If you’re using Msysgit or Cygwin you can find a good tutorial at SSH-Agent in msysgit and cygwin and bash:
-
Add a file called
.bashrc
to your home folder. -
Open the file and paste in:
#!/bin/bash eval `ssh-agent -s` ssh-add
-
This assumes that your key is in the conventional
~/.ssh/id_rsa
location. If it isn’t, include a full path after thessh-add
command. -
Add to or create file
~/.ssh/config
with the contentsForwardAgent yes
In the original tutorial the
ForwardAgent
param isYes
, but it’s a typo. Use all lowercase or you’ll get errors. -
Restart Msysgit. It will ask you to enter your passphrase once, and that’s it (until you end the session, or your ssh-agent is killed.)
Mac/OS X
If you don’t want to start a new ssh-agent every time you open a terminal, check out Keychain. I’m on a Mac now, so I used the tutorial ssh-agent with zsh & keychain on Mac OS X to set it up, but I’m sure a Google search will have plenty of info for Windows.
Update: A better solution on Mac is to add your key to the Mac OS Keychain:
ssh-add -K ~/.ssh/id_rsa
Simple as that.
answered Apr 9, 2012 at 17:43
RobWRobW
9,9164 gold badges41 silver badges40 bronze badges
11
Run
ssh-agent bash
ssh-add
To get more details you can search
ssh-agent
or run
man ssh-agent
answered Oct 11, 2018 at 2:26
bp zhangbp zhang
2,4001 gold badge9 silver badges10 bronze badges
6
ssh-add and ssh (assuming you are using the openssh implementations) require an environment variable to know how to talk to the ssh agent. If you started the agent in a different command prompt window to the one you’re using now, or if you started it incorrectly, neither ssh-add nor ssh will see that environment variable set (because the environment variable is set locally to the command prompt it’s set in).
You don’t say which version of ssh you’re using, but if you’re using cygwin’s, you can use this recipe from SSH Agent on Cygwin:
# Add to your Bash config file
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi
This will start an agent automatically for each new command prompt window that you open (which is suboptimal if you open multiple command prompts in one session, but at least it should work).
answered Nov 3, 2010 at 11:53
Robin GreenRobin Green
31.5k16 gold badges102 silver badges185 bronze badges
5
I faced the same problem for Linux, and here is what I did:
Basically, the command ssh-agent starts the agent, but it doesn’t really set the environment variables for it to run. It just outputs those variables to the shell.
You need to:
eval `ssh-agent`
and then do ssh-add. See Could not open a connection to your authentication agent.
answered Jul 19, 2013 at 6:12
n3on3o
2,7555 gold badges23 silver badges36 bronze badges
3
Instead of using ssh-agent -s
, I used eval `ssh-agent -s`
to solve this issue.
Here is what I performed step by step (step 2 onwards on Git Bash):
- Cleaned up my .ssh folder at
C:user<username>.ssh
- Generated a new SSH key:
ssh-keygen -t rsa -b 4096 -C "xyz@abc.com"
- Check if any process id(ssh agent) is already running.
ps aux | grep ssh
- (Optional) If found any in step 3, kill those
kill <pids>
- Started the SSH agent
$ eval `ssh-agent -s`
- Added SSH key generated in step 2 to the SSH agent
ssh-add ~/.ssh/id_rsa
answered Jan 7, 2016 at 10:31
vinsinrawvinsinraw
1,9571 gold badge15 silver badges17 bronze badges
4
Try to do the following steps:
-
Open Git Bash and run:
cd ~/.ssh
-
Try to run agent:
eval $(ssh-agent)
-
Right now, you can run the following command:
ssh-add -l
answered Nov 26, 2013 at 13:47
ChechoroArtemChechoroArtem
1,2711 gold badge8 silver badges13 bronze badges
5
In Windows 10 I tried all answers listed here, but none of them seemed to work. In fact, they give a clue. To solve a problem, simply you need three commands. The idea of this problem is that ssh-add needs the SSH_AUTH_SOCK and SSH_AGENT_PID environment variables to be set with the current ssh-agent sock file path and pid number.
ssh-agent -s > temp.txt
This will save the output of ssh-agent in a file. The text file content will be something like this:
SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3044; export SSH_AGENT_PID;
echo Agent pid 3044;
Copy something like «/tmp/ssh-kjmxRb2764/agent.2764» from the text file and run the following command directly in the console:
set SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764
Copy something like «3044» from the text file and run the following command directly in the console:
set SSH_AGENT_PID=3044
Now when environment variables (SSH_AUTH_SOCK and SSH_AGENT_PID) are set for the current console session, run your ssh-add command and it will not fail again to connect to ssh agent.
answered Jun 12, 2015 at 13:58
BIOHAZARDBIOHAZARD
1,90720 silver badges23 bronze badges
7
One thing I came across was that eval
did not work for me using Cygwin, what worked for me was ssh-agent ssh-add id_rsa
.
After that I came across an issue that my private key was too open, the solution I managed to find for that (from here):
chgrp Users id_rsa
as well as
chmod 600 id_rsa
finally I was able to use:
ssh-agent ssh-add id_rsa
answered May 28, 2014 at 4:17
VngeVnge
1,29525 silver badges49 bronze badges
3
For Windows users, I found cmd eval `ssh-agent -s`
didn’t work, but using Git Bash worked a treat:
eval `ssh-agent -s`; ssh-add KEY_LOCATION
And making sure the Windows service «OpenSSH Key Management» wasn’t disabled.
answered Mar 20, 2019 at 15:17
aqmaqm
2,90423 silver badges30 bronze badges
4
To amplify on n3o’s answer for Windows 7…
My problem was indeed that some required environment variables weren’t set, and n3o is correct that ssh-agent tells you how to set those environment variables, but doesn’t actually set them.
Since Windows doesn’t let you do «eval,» here’s what to do instead:
Redirect the output of ssh-agent to a batch file with
ssh-agent > temp.bat
Now use a text editor such as Notepad to edit temp.bat. For each of the first two lines:
- Insert the word «set» and a space at the beginning of the line.
- Delete the first semicolon and everything that follows.
Now delete the third line. Your temp.bat should look something like this:
set SSH_AUTH_SOCK=/tmp/ssh-EorQv10636/agent.10636
set SSH_AGENT_PID=8608
Run temp.bat. This will set the environment variables that are needed for ssh-add to work.
answered Dec 19, 2013 at 14:57
Steve SaportaSteve Saporta
4,3713 gold badges28 silver badges32 bronze badges
2
I just got this working. Open your ~/.ssh/config
file.
Append the following-
Host github.com
IdentityFile ~/.ssh/github_rsa
The page that gave me the hint Set up SSH for Git
said that the single space indentation is important… though I had a configuration in here from Heroku that did not have that space and works properly.
answered Feb 25, 2014 at 3:42
Paul BecottePaul Becotte
9,4743 gold badges32 silver badges42 bronze badges
4
If you follow these instructions, your problem would be solved.
If you’re on a Mac or Linux machine, type:
eval "$(ssh-agent -s)"
If you’re on a Windows machine, type:
ssh-agent -s
Weafs.py
22.5k9 gold badges54 silver badges78 bronze badges
answered Nov 8, 2014 at 13:20
Fahim BoronFahim Boron
2012 silver badges4 bronze badges
I had the same problem on Ubuntu and the other solutions didn’t help me.
I finally realized what my problem was. I had created my SSH keys in the /root/.ssh
folder, so even when I ran ssh-add
as root, it couldn’t do its work and kept saying:
Could not open a connection to your authentication agent.
I created my SSH public and private keys in /home/myUsername/
folder and I used
ssh-agent /bin/sh
Then I ran
ssh-add /home/myUsername/.ssh/id_rsa
And problem was solved this way.
Note: For accessing your repository in Git, add your Git password when you are creating SSH keys with ssh-keygen -t rsa -C "your Git email here"
.
answered Jan 16, 2019 at 12:12
AkramAkram
2,1381 gold badge16 silver badges24 bronze badges
Let me offer another solution. If you have just installed Git 1.8.2.2 or thereabouts, and you want to enable SSH, follow the well-writen directions.
Everything through to Step 5.6 where you might encounter a slight snag. If an SSH agent is already be running you could get the following error message when you restart bash
Could not open a connection to your authentication agent
If you do, use the following command to see if more than one ssh-agent process is running
ps aux | grep ssh
If you see more than one ssh-agent service, you will need to kill all of these processes. Use the kill command as follows (the PID will be unique on your computer)
kill <PID>
Example:
kill 1074
After you have removed all of the ssh-agent processes, run the px aux | grep ssh command again to be sure they are gone, then restart Bash.
Voila, you should now get something like this:
Initializing new SSH agent...
succeeded
Enter passphrase for /c/Users/username/.ssh/id_rsa:
Now you can continue on Step 5.7 and beyond.
answered May 2, 2013 at 18:35
RickRick
3251 silver badge7 bronze badges
3
This will run the SSH agent and authenticate only the first time you need it, not every time you open your Bash terminal. It can be used for any program using SSH in general, including ssh
itself and scp
. Just add this to /etc/profile.d/ssh-helper.sh
:
ssh-auth() {
# Start the SSH agent only if not running
[[ -z $(ps | grep ssh-agent) ]] && echo $(ssh-agent) > /tmp/ssh-agent-data.sh
# Identify the running SSH agent
[[ -z $SSH_AGENT_PID ]] && source /tmp/ssh-agent-data.sh > /dev/null
# Authenticate (change key path or make a symlink if needed)
[[ -z $(ssh-add -l | grep "/home/$(whoami)/.ssh/id_rsa") ]] && ssh-add
}
# You can repeat this for other commands using SSH
git() { ssh-auth; command git "$@"; }
Note: this is an answer to this question, which has been merged with this one.
That question was for Windows 7, meaning my answer was for Cygwin/MSYS/MSYS2. This one seems for some Unix, where I wouldn’t expect the SSH agent needing to be managed like this.
answered Jun 22, 2014 at 1:22
6
The basic solution to run ssh-agent
is answered in many answers. However runing ssh-agent
many times (per each opened terminal or per remote login) will create a many copies ot ssh-agent
running in memory. The scripts which is suggested to avoid that problem is long and need to write and/or copy separated file or need to write too many strings in ~/.profile
or ~/.schrc
. Let me suggest simple two string solution:
For sh, bash, etc:
# ~/.profile
if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -s > ~/.ssh-agent.sh; fi
. ~/.ssh-agent.sh
For csh, tcsh, etc:
# ~/.schrc
sh -c 'if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -c > ~/.ssh-agent.tcsh; fi'
eval `cat ~/.ssh-agent.tcsh`
What is here:
- search the process
ssh-agent
by name and by current user - create appropriate shell script file by calling
ssh-agent
and runssh-agent
itself if no current userssh-agent
process found - evaluate created shell script which configure appropriate environment
It is not necessary to protect created shell script ~/.ssh-agent.tcsh
or ~/.ssh-agent.sh
from another users access because: at-first communication with ssh-agent
is processed through protected socket which is not accessible to another users, and at-second another users can found ssh-agent
socket simple by enumeration files in /tmp/
directory. As far as about access to ssh-agent
process it is the same things.
answered Oct 13, 2017 at 19:40
oklasoklas
7,6692 gold badges25 silver badges40 bronze badges
In Windows 10, using the Command Prompt terminal, the following works for me:
ssh-agent cmd
ssh-add
You should then be asked for a passphrase after this:
Enter passphrase for /c/Users/username/.ssh/id_rsa:
answered Jan 25, 2021 at 13:00
AllanAllan
1,11411 silver badges19 bronze badges
2
Try the following:
ssh-agent sh -c 'ssh-add && git push heroku master'
answered Mar 26, 2015 at 21:13
kenorbkenorb
149k80 gold badges667 silver badges722 bronze badges
1
Use parameter -A when you connect to server, example:
ssh -A root@myhost
from man page :
-A Enables forwarding of the authentication agent connection.
This can also be specified on a per-host basis in a configuration file.
Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the agent's
UNIX-domain socket) can access the local agent through the forwarded
connection. An attacker cannot obtain key material from the agent,
however they can perform operations on the keys that enable them to
authenticate using the identities loaded into the agent.
answered Aug 9, 2016 at 13:31
LebnikLebnik
6288 silver badges11 bronze badges
2
I had this problem, when I started ssh-agent, when it was already running. It seems that the multiple instances conflict with each other.
To see if ssh-agent is already running, check the value of the SSH_AGENT_SOCK environment variable with:
echo $SSH_AGENT_SOCK
If it is set, then the agent is presumably running.
To check if you have more than one ssh-agent running, you can review:
ps -ef | grep ssh
Of course, then you should kill any additional instances that you created.
answered Jul 4, 2014 at 8:48
JahmicJahmic
11.2k11 gold badges65 silver badges77 bronze badges
4
Read user456814’s answer for explanations. Here I only try to automate the fix.
If you using a Cygwin terminal with Bash, add the following to the $HOME/.bashrc file. This only starts ssh-agent once in the first Bash terminal and adds the keys to ssh-agent. (I am not sure if this is required on Linux.)
###########################
# start ssh-agent for
# ssh authentication with github.com
###########################
SSH_AUTH_SOCK_FILE=/tmp/SSH_AUTH_SOCK.sh
if [ ! -e $SSH_AUTH_SOCK_FILE ]; then
# need to find SSH_AUTH_SOCK again.
# restarting is an easy option
pkill ssh-agent
fi
# check if already running
SSH_AGENT_PID=`pgrep ssh-agent`
if [ "x$SSH_AGENT_PID" == "x" ]; then
# echo "not running. starting"
eval $(ssh-agent -s) > /dev/null
rm -f $SSH_AUTH_SOCK_FILE
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > $SSH_AUTH_SOCK_FILE
ssh-add $HOME/.ssh/github.com_id_rsa 2>&1 > /dev/null
#else
# echo "already running"
fi
source $SSH_AUTH_SOCK_FILE
Don’t forget to add your correct keys in the «ssh-add» command.
answered Jul 9, 2015 at 5:48
Kiran MohanKiran Mohan
2,4926 gold badges33 silver badges62 bronze badges
I had a similar problem when I was trying to get this to work on Windows to connect to the stash via SSH.
Here is the solution that worked for me.
-
Turns out I was running the Pageant ssh agent on my Windows box — I would check what you are running. I suspect it is Pageant as it comes as default with PuTTY and WinSCP.
-
The ssh-add does not work from command line with this type of agent
-
You need to add the private key via the Pageant UI window which you can get by double-clicking the Pageant icon in the taskbar (once it is started).
-
Before you add the key to Pageant you need to convert it to PPK format. Full instructions are available here How to convert SSH key to ppk format
-
That is it. Once I uploaded my key to stash I was able to use Sourcetree to create a local repository and clone the remote.
answered Nov 17, 2014 at 14:14
MoonwalkerMoonwalker
3,3224 gold badges25 silver badges31 bronze badges
For Bash built into Windows 10, I added this to file .bash_profile:
if [ -z $SSH_AUTH_SOCK ]; then
if [ -r ~/.ssh/env ]; then
source ~/.ssh/env
if [ `ps -p $SSH_AGENT_PID | wc -l` = 1 ]; then
rm ~/.ssh/env
unset SSH_AUTH_SOCK
fi
fi
fi
if [ -z $SSH_AUTH_SOCK ]; then
ssh-agent -s | sed 's/^echo/#echo/'> ~/.ssh/env
chmod 600 ~/.ssh/env
source ~/.ssh/env > /dev/null 2>&1
fi
answered Apr 26, 2016 at 16:07
KipKip
5617 silver badges16 bronze badges
2
Using Git Bash on Windows 8.1 E, my resolution was as follows:
eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa
answered Jun 25, 2014 at 18:47
SrBlancoSrBlanco
1291 silver badge4 bronze badges
5
I resolved the error by force stopping (killed) git processes (ssh agent), then uninstalling Git, and then installing Git again.
answered Apr 19, 2014 at 10:18
Devendra SinghDevendra Singh
811 gold badge2 silver badges9 bronze badges
1
This worked for me.
In the CMD window, type the following command:
cd path-to-Git/bin # (for example,cd C:Program FilesGitbin)
bash
exec ssh-agent bash
ssh-add path/to/.ssh/id_rsa
kenorb
149k80 gold badges667 silver badges722 bronze badges
answered Feb 25, 2015 at 11:44
keccokecco
1968 bronze badges
1
WRITE FOR US
I use WSL with Ubuntu on my laptop to develop on Linux while I’m away from my desktop (with native Linux, where I don’t experience any problems like this). I have private git repo setup, and I use ssh to connect to it. I have ssh configured (in .ssh/config
), and I have multiple keys for my VPS, GitHub, other VPS user account etc. so I use ssh-add
on my desktop to manage them. But on my laptop, in WSL, when I try to connect to my VPS, ssh asks for the passphrase to the key. When I try to do ssh-add .ssh/mykey
I get an error:
$ ssh-add .ssh/mykey
Could not open a connection to your authentication agent.
But ssh-agent
is running:
$ ps -e | grep ssh
4455 ? 00:00:00 ssh-agent
5517 ? 00:00:00 sshd
6164 pts/0 00:00:00 ssh
I don’t see why is there a problem. If I kill currently running ssh-agent
and launch it again (using eval $(ssh-agent -s)
) it works fine.
asked Oct 2, 2018 at 7:08
1
Looks like you are starting ssh-agent but you are not setting up the variable pointing to it.
When you just run ssh-agent
it will output something like:
SSH_AUTH_SOCK=/tmp/ssh-UfASAcTfsiJm/agent.77; export SSH_AUTH_SOCK;
SSH_AGENT_PID=78; export SSH_AGENT_PID;
Copy that as commands and paste to bash, or make your life simpler by just executing:
eval `ssh-agent`
After that variables will be set and ssh-add will know how to connect to ssh-agent.
answered Apr 1, 2019 at 19:22
The problem is that with WSL (as of 2019) you can start multiple shells from the Window subsystem, they are aware of each others but don’t inherit any variables. Therefore they don’t know that ssh-agent is already running.
I managed to get it working by adding this bit of code to my .bashrc:
source /tmp/ssh-agent >/dev/null 2>&1
ssh-add 2> /dev/null
if [ $? -ne 0 ]; then
ssh-agent >/tmp/ssh-agent
source /tmp/ssh-agent >/dev/null 2>&1
ssh-add
fi
Maybe not the most eloquent code, but it solves the problem.
answered Aug 19, 2019 at 13:08
DokbuaDokbua
1416 bronze badges
You might get an error that reads “could not open a connection to your authentication agent” when you try and add a key passphrase by using the ssh-add command. This particular problem is usually caused by the ssh-agent not getting correctly assigned, which is why so many people find it becomes a problem in slightly unusual circumstances.
For instance, you might find that you get this error when using RaspberryPi running Raspbian, an embedded router with a fished out command prompt or an Android Linux terminal. You can easily fix it with a simple command that doesn’t require you to play around at all no matter what type of device that you’re working on or which shell you happen to be working from.
Fixing Authentication Agent Errors
Assuming that you already have the ssh-agent running, you shouldn’t have to start it up again. Instead, you’ll want to try adding your key passphrase by running ssh-add from the command line. When you do, you more than likely receive some kind of error that reads “Could not open a connection to your authentication agent” along with generally no other text at all. This isn’t exactly the most helpful command, and some users find that they play around for a long time before they found the answer because it doesn’t lead them in the path of the right answer.
First off, while it seems a bit pedantic, check to make sure that you’re connected to the Internet or whatever other type of networking protocol you’re working with because it could be that you’re merely not connected to the network. This is especially a problem when you’re working with some kind of non-standard LAN equipment where you are only using ssh over some sort of a private network instead of through Ethernet or Wi-Fi.
As long as you’re sure you’re connected, try using ssh-add ~/.ssh/id_rsa, having replaced the file name with the actual file name of the key that you were trying to add. We actually named the key on our test machine ~/.ssh/id_rsa, which is the name of the sample one though you probably have a different name. You might get a prompt to “Enter passphrase,” which is silent like those in a Linux virtual terminal. Should this accept your passphrase, then you’re perfectly fine and need no further work.
On the other hand, if you get the “Could not open a connection to your authentication agent” error again, the agent needs full reassignment. If you’re working with the regular shell, then just run ssh-agent /bin/sh and then ssh-add ~/.ssh/id_rsa, once again making sure to replace the name of the key. You should have the prompt at this point. Those using pure bash who don’t mind what some in the Linux community refer to as “bashisms” in their ssh client can merely use ssh-agent bash and then use the ssh-add command. Most people will find that both root and regular users have bash in their path and don’t need anything else.
Users of fish-shell will want to try either ssh-agent /usr/bin/fish and then ssh-add ~/.ssh/id_rsa instead. The above, however, would work fine for those using the Bourne, bash or Almquist shells in an overwhelming majority of cases. If things are working now, then you don’t need to do anything else. Those using the C-Shell or tcsh might run into a problem at this point, though.
If you’re in this situation, then try eval ‘ssh-agent -c’ followed by ssh-add ~/.ssh/id_rsa to get your shell agent registered. This is because tcsh does things a bit differently, though most embedded systems and the like won’t have it. In either case, you should have a working ssh connection at this point as long as you’ve typed everything correctly. If you make any mistakes, then you can just repeat the command as none of these are destructive.
Depending on your configuration, you may have to do this each time that you log onto your ssh connection after a restart. In any case, though, the problem is easily fixed with a single command so you won’t have to sit there playing around afterwards.
Kevin Arrows
Kevin is a dynamic and self-motivated information technology professional, with a Thorough knowledge of all facets pertaining to network infrastructure design, implementation and administration. Superior record of delivering simultaneous large-scale mission critical projects on time and under budget.
In this post I will go through ways to fix the error: connection to the authentication agent. This issue is incredibly irritating when you haven’t encountered it before, but the problem is simple, basically the ssh-agent is not running.
We need to ensure that we start the ssh-agent
before we use ssh-add
. If you are using zsh
on Ubuntu or Mac the following should work:
eval `ssh-agent -s`
You could also try the following if the above doesn’t work on your system:
Bash
exec ssh-agent bash
Zsh
exec ssh-agent zsh
Fish
exec ssh-agent fish
Another potential fix
This might sound obvious and not really like much help, but, the best fix that I have found, is to shutdown my computer and restart it. Whenever I have restarted my computer after having this issue, it has worked without issue.
If I don’t feel like restarting I will use the first command provided. Quick note on this, every time you open a new terminal window/tab you might need to run the above.
Conclusion
This is a very irritating problem, but luckily the fix is simple, and hopefully, it is as simple as switching it off and on.
Картина маслом
ssh-add ~/.ssh/mykey_rsa Could not open a connection to your authentication agent.
ЭЭ.. чего? Гуглим.. ок, нет агента, запускаем его.
eval $(ssh-agent -s)
Теперь ключ добавляется. Ладно вроде все окей. Только при следующем коннекте опять та же канитель!! То есть отключился от сервера, зашел под тем же логином и опять 25. Ровно тот же самый вопрос. При этом
ps axu | grep ssh
.. говорит что да-да, ssh-agent запущен и все круто. Но при следующем коннекте мы его не видим все рано. Во дела. Как быть-то..
Я знатно попарился разыскивая решение, но оно тупое как.. В общем убиваем агент, он не нужен будет
killall ssh-agent
Теперь делаем так
cd ~/.ssh/ touch config echo IdentityFile ~/.ssh/mykey_rsa >> ./config
И таки все начинает работать, при условии что ключ сгенерен без парольной защиты, иначе будет трэбовать пароль после каждого нового логина и придется приплясывать снова ещё и с этим. Мне это надо было для автоматизации обновлений через баш-скриптик одной штуки, то есть зашел-запустил-вышел, минимум движений. Буду признателен за решение лучше.
Решение нашел тут.