SyntaxHighlighter JS

2018-10-25

Get the original username of sudo

For auditing and logging purposes, I needed to get the original Unix login username and not the sudo account name.

The Unix command to get the original login username is

logname 

With the logname command, the operator can su and sudo to various accounts and it will still display the original login.

To try it on a Unix prompt

sudo su - oracle
echo My sudo id is $(whoami) and my login id is $(logname)

Output:
My sudo id is oracle and my login id is juttayaya



Reference:https://stackoverflow.com/questions/4598001/how-do-you-find-the-original-user-through-multiple-sudo-and-su-commands

No comments:

Post a Comment