-->

What Is The Difference Between Sudo And Su In Linux ?


What Is The Difference Between Sudo And Su In Linux ?

Short : Many of you might be using sudo and su in terminal every day to accomplish different tasks. While sudo runs a single command with root privileges, su launches another shell instance with the privileges of the intended user. Both, sudo and su, are use to grant root privileges to the users in different manners.

A Linux user comes across sudo and su in terminal very often. If you are a new Linux user, you might be fascinated by the things you can do with sudo and su. Last week, I also told you about a Windows command that you can use to get sudo-like functionality. Sudo and su  provide root privileges in two different ways. But, how are they different? Here, I’ll try to answer this query.

Before telling you the difference, let me tell you the meaning of a root user. The root user in a Linux system has the maximum permissions and he/she can do anything to the systems. Apart from letting a normal user install/delete some package, root user permissions also act as an extra security layer.

Important : One should also note that these functions are used in a different way in different Linux-based operating systems. Most of the things we’ll discuss here are applicable to Ubuntu and its derivatives. They might differ a little bit in other Linux distributions.

Key differences between sudo and su

The su command stands for super user or root user. It executes on a Linux system with no additional options. The user just needs to add root account password. In the terminal, su also lets you access any other user account using the required password. That’s why su also stands for substitute user or switch user. Simply type su followed by the user account name, e.g., sudo fossbytes, and you’ll enter the password for fossbytes. After completing the job, you can exit the root shell by typing exit. Overall, su basically starts another shell instance with the privileges of the intended user.

On the other hand, sudo runs a single command with root permissions. When a user runs a command with sudo, e.g., sudo command, he/she needs to enter the current user account password to run it as root user. Sudo uses a config file (/etc/sudoers) to define the rights of different users. For detailed information on sudo, you can read our detailed article written by Devin — Sudo in Linux

Comparing the both, sudo lets one use the user account password to run system command. On the other hand, su forces one to share the root passwords to other users. Also, sudo doesn’t activate the root shell and runs a single command.

Using sudo and su in Linux distros

Ubuntu was the first widely used Linux distribution that adopted sudo-only approach by default. When one installs Ubuntu Linux, the root account is created without any password. One needs to assign a password to the root account to log in as root. In Ubuntu and many other Debian-based distros, the user needs to remember just a single password. This way, Ubuntu encourages a user to avoid logging in as a root user. In distros like Fedora, a person needs to create different passwords for root and user accounts.

There’s an often-used combination sudo su that Linux users find helpful. First, sudo asks for your password, and, if it’s provided, it runs the next command as a root user. Also, to run a single command as a root user using su, one needs to use this syntax: su -c ‘command’.

Did you find this article helpful? Don’t forget to drop your feedback in the comments section below.




Also Read

Post a Comment