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.
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.