- 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.
gg.gg/13nbnz gg.gg/13p5tj gg.gg/13p9s5 gg.gg/13tljl gg.gg/13xudz gg.gg/13xy3p gg.gg/143tqc linux.die.net linux.it.net.cn ostechnix.com unix.com gg.gg/19yv96 man.linuxde.net gg.gg/148erg bit.ly/2vsM34J bit.ly/2EzoUDo bit.ly/2wCsZSI bit.ly/2v6jGJi bit.ly/2tW6eYT bit.ly/2u2MMtm bit.ly/2X6vadl bit.ly/2viLpHU bit.ly/2fzzbEU linuxprobe.com linuxtechi.com ttlsa.com systutorials.com ghacks.net linuxopsys.com reurl.cc/8W1x3X reurl.cc/NpzMWe reurl.cc/WrgYdx reurl.cc/Yv4Yvo reurl.cc/Lmy90K reurl.cc/Rr5aeG
Total Pageviews
Thursday 16 November 2017
su, sudo, and environment
Labels:
linux
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment