0

I set up an SSH server that contains a git repository. I have a user that can remotely connect to that ssh server using SSH keys (generated with ssh-keygen and then communicated to the server with ssh-copy-id), so that when I use the command ssh git@serverIP it connects without requiring the user to type the server password.

But when that same user tries to push to the repository with git push it asks for the server password, as if the user never shared the SSH key. I suppose I have to configure the git repository to use the SSH keys, as this question addresses in the case of gitlab repositories. Note that i'm not using GitHub either.

Using git remote -v gives:

origin git@serverIP:repository.git (fetch)
origin git@serverIP:repository.git (push)

My goal is to be able to execute a script that can push to the repository without needing user interaction, i.e. without asking the password. Any idea? Help would be much appreciated...

Edit:

Setting up again the repository actually fixed the problem. As a side note, when executing the script it still asked for the password: the problem was that I was executing the script with sudo, meaning that it was no longer the user to push to the repository, but root (that didn't have SSH keys). Hope this note can help someone else.

  • 1
    Can you edit your question to include the output of `git remote -v`? – bk2204 Feb 18 '22 at 15:09
  • This implies that you have two different URLs set up for the repository: the fetch URL uses ssh and the push URL doesn't. That would show up in `git remote -v` output. – torek Feb 19 '22 at 08:40
  • Thank you for the comments, I actually tried setting up again the repository and it now it works. – Massimiliano Torchio Feb 19 '22 at 16:26
  • You can also consider [this cross-site Q/A](https://unix.stackexchange.com/questions/26371/ssh-prompts-for-password-despite-ssh-authorized-keys#comment35605_26371) or [these](https://stackoverflow.com/questions/7773181/git-keeps-prompting-me-for-a-password) [potential](https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password) [duplicates](https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password) – Cadoiz Oct 07 '22 at 08:47

0 Answers0