1

In my server, I created the ssh keys by using ssh-keygen, put a password and left all else in default. The file is successfully created in /home/user/.ssh/. Great.

Added the public key to my GitLab account. Great.

Then I went to the directory where I want to copy the repository and did git clone using sudo (sudo git clone git@gitlab.com:project/projectname.git) and get the following output:

git@gitlab.com: Permission denied (publickey). fatal: Could not read from remote repository.

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


I do have the right permissions and correctly added the public key in my Gitlab account - I know this because if I do a git clone without the sudo keyword, I get the following error:

fatal: could not create work tree dir 'projectname': Permission denied

This tells me that git clone is accessing the repository successfully, it just can't write into my present working directory. (Am I correct?)

To confirm the above, I went to my home directory and performed a git clone without the sudo keyword, and the repository was successfully copied into my server's home directory, /home/user/...

What's going on?

To get around this, I simply 'sudo mv' the copied repository in my home directory into my web directory where I intended to clone.

I am not confident that this is a solid solution thought it gets the job done


I read in other posts some commenters say that if I use 'sudo' before cloning, that the process will look for rsa keys in the /root/.ssh instead of /home/user/.ssh


Other information to help you help me:

  • logged into DigitalOcean Ubuntu Server via ssh, 'ssh user@ipaddress', entered rsa password
  • using GitBash on Windows 10
  • the 'user' has sudo privileges
  • created the ssh keys in the server using 'user' with sudo
  • ssh key is 4096 bits key with password

Thank you.

3
  • Your question is confusing, the question in your title was already answered in the questions body (I read in other posts some commenters say that if I use 'sudo' before cloning, that the process will look for rsa keys in the /root/.ssh instead of /home/user/.ssh), so I have no idea what question you're really asking.
    – tkausl
    Oct 30, 2018 at 16:33
  • Can you not just download a zip of the repository then upload the contents via Filezilla? Oct 30, 2018 at 16:33
  • @tkausl - well it just doesn't make sense to me why using sudo on a user with sudo privileges forces the system to look in the /root folder, even though the 'sudo' group and users assigned in this group grants elevated access and simulate root, using sudo shouldn't jump out of the home directory and into root (right?). In my experience, this has only happened to me on a CloudServer and not on local environments that I run in VM's. Hope that this helps to clear out my question.
    – El Sordo
    Oct 30, 2018 at 17:56

1 Answer 1

0

I had the same problem when I was trying to git clone while signed in as a user on Digital Ocean. I got around it by navigating to the .ssh directory for the user, generating a pair of ssh keys and then adding the .pub version to my github account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.