Search code examples
gitsshprivileges

Git: Permission denied when trying to access git repo


I am trying to start working on my code using GIT.

On my server the folder /root/git/apotheke/dienstplan was set up as git repo.

git init

When I am trying to get a local copy of the data I get an error:

git clone ssh://bruno@bruno-xxx.de/root/git/apotheke/dienstplan/ Klone nach 'dienstplan' ... standard in must be a tty fatal: '/root/git/apotheke/dienstplan' does not appear to be a git repository fatal: Could not read from remote repository.

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

So I tried

ssh -vT bruno@bruno-xxx.de:/root/git/apotheke/dienstplan/ ssh: Could not resolve hostname bruno-xxx.de:/root/git/apotheke/dienstplan/: Name or service not known

But when I omit the folder it works.

ssh -vT bruno@bruno-xxx.de

What did I miss? Where can I find a clue for the error? How can I access my git repo?

Update: It was a problem of user privileges. Although I had changed the group of the folder /root/git/apotheke/dienstplan/ to "bruno" recursively I had no access to it. After moving the dirctory into the /home/bruno/ directory I changed the owner to bruno:bruno. Now everything works:

git clone ssh://bruno@bruno-xxx.de:/home/martin/git/apotheke/dienstplan Klone nach 'dienstplan' ... standard in must be a tty remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. Empfange Objekte: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Prüfe Konnektivität ... Fertig.


Solution

  • What did I miss?

    That you are doing it wrong :-)

    ssh://bruno@bruno-xxx.de/root/git/apotheke/dienstplan/ is not a valid URL, so it's unsurprising you get an error for that.

    For the second command, ssh takes a hostname, and that is not a hostname.

    For the third command, that is a hostname, so it works.

    All totally unsurprising.

    If you still get an error when you add the missing : to the first command then you need to check that the directory path is correct. You've already confirmed that you can connect to the host (that's what the third command shows) so do:

    ssh -vT bruno@bruno-xxx.de 'ls /root/git/apotheke/dienstplan/'
    

    If that works then the directory exists. If it shows the Git repo contents, then it's a valid repository. If it doesn't work, or doesn't show the repo contents, then you have got the directory path wrong.