If you’re a Linux user, you’ve probably seen references to both sudo and su. Sometimes starting out as a new Linux user isn’t really easy. Thank God for the internet, we have Google search to help us out. With Google search you probably will get a few code tips that will definitely help you achieve what you want. While this is good, you may realize you get the job done but never really understand the basics of how stuff works (Did someone scream AM NO GEEK!).
Sudo and su are two different ways to gain root privileges. Each functions in a different way, and different Linux distributions use different configurations by default.
The Root User
Both su and sudo are used to run commands with root permissions. The root user is basically equivalent to the administrator user on Windows – the root user has maximum permissions and can do anything to the system. Normal users on Linux run with reduced permissions – for example, they can’t install software or write to system directories.
To do something that requires these permissions, you’ll have to acquire them with su or sudo.
Su vs. Sudo
The su command switches to the super user – or root user – when you execute it with no additional options. You’ll have to enter the root account’s password. This isn’t all the su command does, though – you can use it to switch to any user account. If you execute the su mark command, you’ll be prompted to enter Bob’s password and the shell will switch to Bob’s user account.
Once you’re done running commands in the root shell, you should type exit to leave the root shell and go back to limited-privileges mode.
Sudo runs a single command with root privileges. When you execute sudo command, the system prompts you for your current user account’s password before running commandas the root user. By default, Ubuntu remembers the password for fifteen minutes and won’t ask for a password again until the fifteen minutes are up.
This is a key difference between su and sudo. Su switches you to the root user account and requires the root account’s password. Sudo runs a single command with root privileges – it doesn’t switch to the root user or require a separate root user password.