- sudo -isudo -i [command] If command is omitted, it spawns a login shell of the target user (usually root) modifying the environment. Otherwise, the command is passed to the shell for execution.
- sudo -ssudo -s [command]If command is omitted, it spawns spawns a login shell of the target user (usually root) without modifying the environment. Otherwise, the command is passed to the shell for execution.This command is useful if you want to keep the environment variables (such as HISTFILE for history) when executing sudo. Use env or declare to see the environment.Note that if always_set_home is enabled in /etc/sudoers (with a line Defaults always_set_home), after you execute sudo -s, the HOME will be changed to the homedir of the target user, as if you execute sudo -sH.
- sudo bash -csudo bash -c 'command string'As a regular user, the following command will fail:sudo ls > /root/ls.txtBecause although the shell that sudo spawns executes ls with root privileges, the non-privileged shell that the user is running redirects the output.As a solution, use the following command:sudo bash -c 'ls > /root/ls.txt'bash -c spawns a shell that executes the string following the option and then terminates. The sudo utility runs the spawned shell with root privileges (without modifying environment).
- su -csu -c 'command string'Similar to the previous one, su -c runs a command with root privileges and returna to original shell after execution.For example,su -c 'ls > /root/ls.txt'In conclusion, 1, 2 and 3 uses sudo utility to execute single commands and have the advantage of not requiring root password.
看得透又看得远者prevail. ppt.cc/flUmLx ppt.cc/fqtgqx ppt.cc/fZsXUx ppt.cc/fhWnZx ppt.cc/fnrkVx ppt.cc/f2CBVx
ppt.cc/fVjECx ppt.cc/fEnHsx ppt.cc/fRZTnx ppt.cc/fSZ3cx ppt.cc/fLOuCx ppt.cc/fE9Nux ppt.cc/fL5Kyx ppt.cc/fIr1ax ppt.cc/f71Yqx tecmint.com linuxcool.com linux.die.net linux.it.net.cn ostechnix.com unix.com ubuntugeek.com runoob.com man.linuxde.net ppt.cc/fwpCex ppt.cc/fxcLIx ppt.cc/foX6Ux linuxprobe.com linuxtechi.com howtoforge.com linuxstory.org systutorials.com ghacks.net linuxopsys.com ppt.cc/ffAGfx ppt.cc/fJbezx ppt.cc/fNIQDx ppt.cc/fCSllx ppt.cc/fybDVx ppt.cc/fIMQxx ppt.cc/fKlBax
Total Pageviews
Thursday, 16 November 2017
su, sudo, and environment
Labels:
linux
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment