sudo vs su
su
- switch user by default to root user
- opens a shell to run command
- prompts for root password
su
run program as root and asks for root password
su username
“su -” vs “sudo -i”
both does same
“su” vs “su -”
-
“su” does not change
- current working dir
- aliases
- env
-
“su -”
- change current working dir
- sets env as if logged in as root
sudo
- runs command as root in the same shell.
- sudo -> su do switch user and do a command
- sudo su will not prompt for root password, when required it ask current user password every 5 mins
sudo -s
will check /etc/sudoers (and possibly included files) to see if the user running it has permission to run a shell as root.
- The user gets a shell as root with no password required
- The user is prompted for a password, and if they type in their own password, they get a shell as root.
- The user is prompted for the root password (this is a weird ‘sudo’ configuration which I don’t understand the reason behind because it mostly duplicates ‘su’, but whatever).
- The user is not allowed at all and an E-mail is sent to root hollering about so-and-so trying to run something as root.
-
- “-” really shorthand for “-l” or “—login”
- causes you to actually log in as that user (by default the superuser).