Last active
October 2, 2022 18:42
-
-
Save ThinGuy/be9ab38a60e9e099b72c79f4e567d163 to your computer and use it in GitHub Desktop.
Illustrate sudo preserving the users's environment ($HOME is this case)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show value of $HOME when user does not preserve the environment | |
sudo bash -c 'echo $HOME' | |
# Show the value of $HOME when -E to preserve the sudo user's environment | |
sudo -E bash -c 'echo $HOME' | |
# Tip: If both are the same: | |
# | |
# - You ran this command directly as root (naughty!) | |
# | |
# - sudo has HOME listed under "env_keep" | |
# - - Check /etc/sudoers and /etc/sudoers.d/* for sudoers files with env_keep set | |
# - - You may check the current value of env_keep with the following command: | |
# (sudo sudo -V|awk '/preserve:[\r]?$/,/^Loc/{if (/^E|^Lo/) next;gsub(/\t|\r/,"");print}'|sort -uV) | |
# # Note: repeated sudo command is intentional | |
# | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.