Sudo git as another user with ssh-agent to access keys

I have an ssh-agent setting for user www data and a password saved for the private key

from root I need to run "sudo -u www-data git pull" so that it does not ask for the git private key password. sudo does not run the .bashrc script, so not sure how to do this?

any suggestions?

+6
source share
2 answers

Maybe you need the -i option? From man sudo :

-i [command]

The -i (simulate the initial login) starts the shell specified in the passwd (5) entry of the target user as the login shell. This means that user-specific resource files, such as .profile or .login, will be read by the shell. If a command is given, it is passed to the shell for execution. Otherwise, the interactive shell is executed.

+2
source

I do this and do ssh-add as part of my .bash_profile:

 sudo -u otherusername ssh-agent bash -l 

Unfortunately, I have no history when I use the up arrow in doing this. However, I execute the same command minus the sudo part.

By the way, this is what I have in my bash profile to automatically run ssh-agent (only once) and add the RSA key (only once):

 # Start ssh-agent & add key if [[ -z $SSH_AGENT_PID ]]; then echo Starting ssh-agent automatically... ssh-agent bash -l elif [[ 0 == `ssh-add -l | grep "(RSA)" -c` ]]; then echo Adding ssh key automatically... # you might have your key in a different location: ssh-add ~/.ssh/idents/id_rsa fi 
+3
source

Source: https://habr.com/ru/post/907731/


All Articles