Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make git clone with sudo

Tags:

git

linux

ssh

sudo

when I make git clone with ssh from a user prompt it works properly.

git clone ssh://URL.com/soft.git soft_git

the ssh key id_rsa and id_rsa.pub are under /home/user/.ssh

my purpose is the execute git with sudo but I got the following error

Cloning into '/home/user/git/soft'...
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

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

I create a folder /root/.ssh and I copy the ssh keys into it but I got the same error

how to execute git with sudo properly.

like image 486
Anis_Stack Avatar asked Jan 21 '16 06:01

Anis_Stack


1 Answers

When you run git using sudo, git will run as root. Because git is running as root, ssh is running as root. Because ssh is running as root, it is trying to log on to the remote server as root. The remote server is not okay with this (as it should be!)

You will need to do two things:

  • Put the username in your URL: ssh://[email protected]/soft.git.

  • Make your SSH key available to the root user, because it will look under /root/.ssh instead of /home/user/.ssh. (You could also probably point SSH at the correct key, but I don't know how to do this, and SSH is picky about permissions.)

like image 80
Dietrich Epp Avatar answered Sep 21 '22 14:09

Dietrich Epp