It took me a while to figure out that “sudo -s” was usually what I wanted in Ubuntu. On these forums, I see people using “su” and “su -l” and other variants.
Below are some notes I collected/edited for Ubuntu. Would anyone be kind enough to suggest edits so I can use these notes for opensuse? (Let’s make these notes into an opensuse “super user” mini-tutorial.)
[ubuntu] How is root’s PATH set? - Ubuntu Forums]([ubuntu] How is root's PATH set?)
sudo su with su you are basically root, but your own environmental variables are "preserved".
sudo -s And your environmental variables are merged with that of root's.
sudo -i On the other hand is "true" root access. None of your variables are carried over and only the root Defaults remain.
I tried “sudo -i”, “sudo -s”, “sudo bash”, and “sudo su”, and ran
env > env-{i,s,bash,su} after each one. This is what I found out:
corrupted by user's HOME=/root root's PATH env vars sudo -i Y [2] N sudo -s N [2] Y sudo bash N [2] Y sudo su Y [1] Y
[1] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
probably set by /etc/environment
[2] PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
[ubuntu] Adding variables to the ROOT account $PATH - Ubuntu Forums]([ubuntu] Adding variables to the ROOT account $PATH)
[ubuntu] How is root’s PATH set? - Ubuntu Forums]([ubuntu] How is root's PATH set?) (same as link above)
To start a root shell (i.e. a command window where you can run Root commands), starting Root’s environment and login scripts, use:
sudo -i (similar to sudo su - , gives you roots environment configuration)
To start a root shell, but keep the current shell’s environment, use:
sudo -s (similar to sudo su)
For a brief overview of some of the differences between su, su -, and sudo -{i,s} see : Ubuntu Forums Post with nice table .
For a detailed description of the differences see man su and man sudo .
RootSudoTimeout
By default sudo remembers your password for 15 minutes. If you want to change that you can do so by
sudo visudo
This opens an editor and points it to the sudoers file – Ubuntu defaults to nano, other systems use Vi. You’re now a super user editing one of the most important files on your system. No stress!
(Vi specific instructions noted with (vi!). Ignore these if you’re using nano)
Use the arrow keys to move to the end of the Defaults line.
(vi!) press the A (capital "a") key to move at the end of the current line and enter editing mode (append after the last character on the line). Now type
,timestamp_timeout=X
where X is the timeout expiration in minutes. If you specify 0 you will always be asked the password. If you specify a negative value, the timeout will never expire. E.g. Defaults env_reset,timestamp_timeout=5
(vi!) hit Escape to return to command mode. Now, if you're happy with your editing, type in :w <ENTER> to write the file and :q <ENTER> to exit vi. If you made a mistake, perhaps the easiest way is to redo from start, to exit without saving (hit Escape to enter the command mode) and then type :q! <ENTER>.
hit CTRL + X, then Y, then <ENTER> to save your file and exit nano.
You might want to read the sudoers and vi manual pages for additional information.
man sudoers
man vi