Unable to clone GitHub private repo "Permission denied (publickey). fatal: Could not read > from remote repository"

md flag

I asked for help on stackoverflow and I was told it is more than likely a Ubuntu problem and was recommended to ask here.

I'm trying to clone a private git repo to my web folder on Ubuntu. I've created the SSH key pair & added it to my account settings on githubs end.

ssh-add ~/.ssh/id_ed25519

> Identity added: /home/ubuntu/.ssh/id_ed25519  (email)

ssh -vT

> Hi CNRP! You've successfully authenticated, but GitHub does not
> provide shell access. debug1: channel 0: free: client-session,
> nchannels 1 Transferred: sent 2148, received 2336 bytes, in 0.2
> seconds Bytes per second: sent 10468.5, received 11384.7

I've tried the following and all respond with similar errors.

git clone

> fatal: could not create work tree dir 'project-name': Permission
> denied

sudo git clone

> Permission denied (publickey). fatal: Could not read
> from remote repository.
> Please make sure you have the correct access rights and the repository
> exists.

git clone

> fatal: could not create work tree dir 'project-name': Permission
> denied

The folder I'm trying to clone to is the /var/www/ web folder. I'm thinking its possibly something todo with user permissions? I've troubleshooted all the github authentication steps and repeated it multiple times so I'm thinking the SSH authentication isn't the problem.

Any help on what I can do from here to work this out is highly appreciated, Its left me stumped!

hr flag
When you use `sudo`, git is presumably looking for SSH keys in root's home directory
CNRP avatar
md flag
Makes a lot of sense actually! thanks for the help.
muru avatar
us flag
Don't use `sudo` in the first place - fix the permissions of the directory so that your user has the necessary access rights for it.
CNRP avatar
md flag
Yeah I will be going that route now I know the route of the issue, I was just trying to narrow down what could be wrong initially.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.