Su VS sudo su VS sudo -u -i
johnkpaul.tumblr.com
johnkpaul.tumblr.com
This is not correct. su does not change the ownership of the pts (tty), so for example you can not run screen after doing that.
I actually have no idea how to change to a different user and also setup the pts properly, so I've resorted to telneting to localhost when I need to do that.
Neither invocation changes the working directory, which is convenient.
$ sudo su - # root
$ sudo su - username # user
$ man su
-, -l, --login
make the shell a login shellman sudo
=> sudo -s
hard uh. always read the f. man damnit. you know, that's what RTFM means.
Edit: just added the last phrase. "without needing a password".
sudo su - <username> takes me to the homefolder of the user and allows me to switch without remembering the password for all of the different users. If I need to do some system-level operation, I open a new tab and run the superuser there.
Using plain su instead of sudo <command> forces me to enter my password, thereby encouraging a concious decision about whether a command needs to be run as root, and the change in prompt is another reminder to be careful.
Defaults timestamp_timeout = 0
in your sudoers file to make sure sudo always prompts for a password. I think this should be default, since the current default of 5 minutes is an easy privilege escalation vector [2].Also, if you like entering root's password instead of your own, you can set the `runaspw` option.
[1]: Unless you'd like to remove one more possible SUID vulnerability.
[2]: It's far from the only way for a local process to escalate privileges, so I understand it's nothing worth yelling about.
I find not having to enter a password for a certain period of time rather annoying, especially when ssh is lagging or when I am typing without paying much attention. If you so wish, you can also set the option "rootpw" for the above, which will make sudo require the root password.
I also set a small number of specific commands to require no password for sudo, mainly for common things like network configuration and suspending. These are defined for the absolute paths of the executables, and only for my user, so they aren't a security risk.
I use `sudo -i` daily, but when doing things that would require things to be in root's path (eg `service` on RHEL envs).