11

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!

  • Hmm, related if not dup: this & this, perhaps even this – ilkkachu Mar 18 '17 at 13:13
  • 2
    I would rather start with "what are you trying to achieve" and "why do you do what you do?". What is your ssh-agent before you run a new one? What does echo $SSH_AUTH_SOCK print before starting the agent? In what format is your id_rsa key? – Jakuje Mar 18 '17 at 14:06

3 Answers3

5

below is based on another answer:

In order to not have to refill 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
0

Add your ssh key file - id_rsa to the directory ~/.ssh/

Use copy or move to place it there rather than the ssh-add

This is the private file that start with:

-----BEGIN RSA PRIVATE KEY-----

If you don't have a private key file, maybe the issue is that your actually need to generate them

  • Open a terminal on your local computer and enter the following: ssh-keygen -t rsa -C "your_email@example.com" ...
  • Just press to accept the default location and file name. ... Enter, and re-enter, a passphrase when prompted. ...
  • You're done!

These steps are from https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html

  • 4
    The OP mentions ~/.ssh/id_rsa — what makes you think it's missing or invalid? – Stephen Kitt Mar 18 '17 at 13:27
  • Because that is within the context of the ssh-add command. Maybe there's an issue with that is what I thought. – Michael Durrant Mar 18 '17 at 20:52
  • 1
    When the OP does that, the push works, which suggests the ssh-add command worked too. It sounds more like the SSH agent is dying for some reason (or no longer responding on its socket, which happens with GNOME’s keyring daemon on my system). – Stephen Kitt Mar 18 '17 at 20:55
  • Sure @StephenKitt you are correct. My answer is somewhat like a comment, but obviously far too long. It's meant more for the OP to try it as investigative and maybe it'll work or maybe it'll show an error. Maybe not. – Michael Durrant Mar 19 '17 at 03:17
0

Having tried suggestions like changing file/directory permissions and ssh-add, a gitlab documentation helped me solve a similar issue.

Have you tried ed25519 instead of rsa?

It is important to check if the encryption type used by your public key is supported by the server you are connecting to. For example, a gitlab server I was trying to did not support the type of keys usually stored in ~/.ssh/id_dsa.pub

Instead, it required ed25519 or rsa encrypted keys. For ed25519, to generate a new key, one can use : $ssh-keygen -t ed25519 -C "email@example.com"

Then, $ssh -T user@server should offer a good check if this key is accepted and a connection can be established.