Search code examples
gitauthenticationurllocal

Local GIT server authentication


I just setup a VM (Ubuntu Server 20.04.2), I setup GIT server on it which is working.

When I run git clone git@VM-IP:repos/repo it is cloning repo from repos dir in git's account home dir (or basically /home/git/repos/repo).

After I run the clone it is asking for password. If I use the git's account password it clones successfully. If I use passwordA (also tried with user@VM-IP.. as well) it is failing. I created .ssh/authorized_keys in /home/git in which I put the result of execution of ssh-keygen -t rsa from user in which I enter passwordA.

After browsing this issue for a while I've found a couple of url formats:

1) git@VM-IP:repo-path
2) git@VM-IP:user/repo-path
3) user@VM-IP:repo-path

Which of those is correct if I want to use user's password to clone the repo from /home/git/repo? Also am I missing something with the keys or is it just URL issue?


Solution

  • Two things that were holding me back.

    1. git had password. If that is your case run sudo passwd -d git from your main user.
    2. There was one invalid key in the file so it was not reading it. For successful authentication you need user to generate rsa pair with ssh-keygen -t rsa and it should be in /home/user/.ssh, keep it there. Copy the content from id_rsa.pub into /home/git/.ssh/authorized_keys (Note that one line = one record!). Now if you do sudo su user; git clone git@localhost:repos/repo it will ask you for password of user and will clone /home/git/repos/repo into /home/user/repo.

    With those two things everything is working now. Thanks for the replies!