- 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.
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 bit.ly/2EzoUDo bit.ly/2tW6eYT bit.ly/2X6vadl bit.ly/2viLpHU linuxprobe.com linuxtechi.com howtoforge.com linuxstory.org systutorials.com ghacks.net linuxopsys.com v.gd/2P9wTx v.gd/FtfpqE v.gd/eMfHsm v.gd/Ub7mqv v.gd/RReVk0 v.gd/vS3uTI v.gd/4Zxmba
Total Pageviews
Thursday, 16 November 2017
su, sudo, and environment
Labels:
linux
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment