I have to use sudo to run my program:
sudo ./my_program
I am trying to run git clone from my program, but it tries to use the root user’s SSH keys instead of mine.
Is there a way to execute this single command as the user who originally invoked my program?
I guess I can do:
su - original_user -c "git --version"
But how do I figure out the username of the original user? Or is there another elegant solution this?
The
sudomanual shows that$SUDO_USERshould give you the original user’s username and$SUDO_UIDgives the original user’s UID.