You can just restart agent by eval ssh-agent -s and add older key using ssh-add ~/. ssh/id_rsa. If you generate new SSH key then you will need to update that key in all your services such as github, bitbucket, etc.
The problem is that every time you reboot, your ssh-agent-session is lost and you have to add the key again. As a workaround you can install a small utility called fish_ssh_agent (or: fish-sshagent) which will start the ssh-agent when running fish shell.
The SSH agent ( ssh-agent ) is an SSH key manager that stores the SSH key in a process memory so that users can log into SSH servers without having to type the key's passphrase every time they authenticate with the server.
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:
To automatically start ssh-agent and allow a single instance to work in multiple console windows, see Start ssh-agent on login.
eval
instead of just ssh-agent
?To find out why, see Robin Green's answer.
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?
I tried the other solutions to no avail. I made more research and found that the following command worked. I am using Windows 7 and Git Bash.
eval $(ssh-agent)
More information in: https://coderwall.com/p/rdi_wq
The following command worked for me. I am using CentOS.
exec ssh-agent bash
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
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 the ssh-add
command.
Add to or create file ~/.ssh/config
with the contents
ForwardAgent yes
In the original tutorial the ForwardAgent
param is Yes
, 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.)
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.
Run
ssh-agent bash
ssh-add
To get more details you can search
ssh-agent
or run
man ssh-agent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With