Updated Template (markdown)

koalaman
2014-02-19 12:42:19 -08:00
parent 29b54e9d18
commit d79b51887a

@@ -1,35 +1,17 @@
# To run commands as another user, use su -c or sudo. # (Message goes here)
### Problematic code: ### Problematic code:
./configure (Simple example of problematic code)
make
su root
make install
### Correct code: ### Correct code:
./configure (Simple example of above code, only fixed)
make
sudo make install # or su -c 'make install' root
### Rationale: ### Rationale:
`su` doesn't actually switch user. It starts a brand new shell, running as another user. You can't put `su foo` in a script to make the following command run as user `foo`. (An explanation of why the code is problematic and how the correct code is an improvement)
Use `sudo -u username cmd` or `su -c cmd username` instead.
### Contraindications ### Contraindications
If you want to present the user with a root shell or when you're redirecting input, you can ignore this message: (Cases where the user may choose to ignore this warning, if any.)
until mycommand
do
echo "Failed. You will now get a root shell. Fix problem and exit to retry."
su
done
or
exec < mycommands
su foo