Updated Template (markdown)

koalaman
2014-02-16 19:00:53 -08:00
parent 35ca8bb923
commit 3ebfab94b4

@@ -1,17 +1,35 @@
# (Message goes here) # "To run commands as another user, use su -c or sudo.
### Problematic code: ### Problematic code:
(Simple example of problematic code) ./configure
make
su root
make install
### Correct code: ### Correct code:
(Simple example of above code, only fixed) ./configure
make
sudo make install # or su -c 'make install' root
### Rationale: ### Rationale:
(An explanation of why the code is problematic and how the correct code is an improvement) `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`.
Use `sudo -u username cmd` or `su -c cmd username` instead.
### Contraindications ### Contraindications
(Cases where the user may choose to ignore this warning, if any.) If you want to present the user with a root shell or when you're redirecting input, you can ignore this message:
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