Ssh – How to avoid using ‘ssh-add ~/.ssh/id_rsa’ for every push to a github repo

gitgitlabssh

I have to repeatedly enter the following terminal commands in order to be able to push to a remote github repository. If I push to github, and then code some more for the next few hours before pushing again, I have to enter the commands:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Otherwise I get the following error messages:

>> git push origin master

sign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey). fatal: Could not read from remote
repository.

Please make sure you have the correct access rights and the repository
exists.

What do I have to do so that I will no longer need to keep using ssh-add in order to be able to push? I would have thought that using ssh-add once would have fixed the issue but it seems that isn't the case!

Best Answer

below is based on another answer:

In order to not have to fill in your password even after a restart add the following to your ssh configuration file (which is commonly located at ~/.ssh/config, or on Windows at %UserProfile%/.ssh/config)

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa
Related Question