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.