Question

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?

Était-ce utile?

La solution 2

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"

Autres conseils

Your environment might be the issue (sudo scrubs some of the environment, and leaves the rest).

I'd try dropping su and use the sudo's -u flag in combination with the -i flag to simulate login conditions:

sudo -u quantka -i git fetch
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top