How to execute a command as a source user from a sudo'd program?

I need to use sudoto run my program:

 sudo ./my_program

I am trying to run git clonefrom my program, but instead I am trying to use SSH keys for the root user. Is there a way to execute this single command as the user who originally called my program?

I think I can do:

su - original_user -c "git --version"

But how can I determine the username of the original user? Or is there another elegant solution?

+5
source share
2 answers

The manual sudoshows what $SUDO_USERshould indicate the original username and $SUDO_UIDgives the original UID of the user.

+3
source

Samba NAS -.

, samba. . , ?

, ps . , , bash.

0

All Articles