

On the other hand, other Linux distributions, such as Fedora, create a root and user account upon installation. To enable the root user, you need to activate it manually. While installing an Ubuntu OS, you create a user automatically labeled as part of the sudoers group.

For this reason, all Ubuntu-based releases are sudo-only, meaning the root account is not active by default. Linux discourages working as root as it may cause unwanted system-wide changes and suggests using sudo instead. It is the traditional way to switch to the root account. Su is an older but more fully-featured command included in all Linux distributions. How sudo and su Work on Different Linux Distributions
#Su vs sudo how to#
Note: For an in-depth guide, refer to How to Add User to Sudoers Group on Ubuntu or How to Add User to Sudoers Group on CentOS. The output should display the account added in the previous step: To see a list of accounts that belong to the sudoers group run: sudo getent group sudo To add a user to the sudoers group, run the following command (as root or an account that already has sudo privileges): usermod -aG sudo įor instance, to add the account phoenixnap, you would type: sudo usermod -aG sudo phoenixnap Adding a User to the Sudoers Groupįor a user to execute a command that requires the sudo prefix, it has to be part of the sudoers group.
#Su vs sudo password#
In such cases, it is recommended to use sudo.īefore the system executes the command, it asks for the password of the current user.īear in mind that the sudo option can only be used by users who belong to the sudoers group. Unlike su, the sudo command in Linux requires providing the password for the user running the command.Īll administrative and executable tasks require maximum permission (held by root). sudo su will execute commands as root in your present working directory but sudo -i will take you to your root's home directory (by default to /root) Another difference is if you are using anything other than bash as. Sudo is used as a prefix to Linux commands, which allows the logged in user to execute commands that require root privileges. As pointed by the user user535733 in the comments section, both commands will take you to different working directory. įor more details about the su command, see our article on How to Use the su Command With Examples.

Note: Additional attributes that allow moving to another user and its login interface include: su - l (or -login). If the command is used without the argument, it switches to the superuser ( root) account. It does this by starting a login shell in the current directory and environment ( su) or by completely changing to the setting of the target user ( su -). The su command stands for substitute user, and it is mostly used for switching from one user to another. On the other hand, su switches to the root user completely, exposing the entire system to potential accidental modification. By doing so, the current user is only granted privileged for the specified command. Therefore, it is much safer to use sudo since it doesn’t include exchanging sensitive information.Īdditionally, it is advisable to stick to sudo when performing tasks that require root privileges. The main difference between the two is that su requires the password of the target account, while sudo requires the password of the current user. Comparison Between Web 1.0, Web 2.0 and Web 3.Both su and sudo elevate privileges assigned to the current user.Python | Difference Between List and Tuple.Difference between Clustered and Non-clustered index.Difference between Primary Key and Foreign Key.Difference between Structure and Union in C.Differences between Procedural and Object Oriented Programming.Differences between Black Box Testing vs White Box Testing.Difference between comparing String using = and.Class method vs Static method in Python.ISRO CS Syllabus for Scientist/Engineer Exam.ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys.
