I'm having a weird permissions issue. It seems that being logged in as a particular user I have different permissions than when I sudo su into that user.
Using su to become quantka causes a git permissions error:
sudo su quantka -c "git fetch"
conq: repository access denied.
fatal: The remote end hung up unexpectedly
But just being logged in as quantka works:
quantka@quantka:~$ whoami
quantka
quantka@quantka:~$ git fetch
quantka@quantka:~$
To add to the mystery, this also works:
quantka@quantka:~$ su quantka -c "git fetch"
Password:
But this isn't a viable solution because this needs to be run from a script, can't prompt for password.
I thought these were supposed be identical?
It turns out this was an environment variables issue. The relevant environment variable for ssh access to the remote git repo is SSH_AUTH_SOCK
.
Adding the -E
flag to the sudo command specifies that environment variables should be preserved, so this works:
sudo -E su quantka -c "git fetch"