Full width home advertisement

Post Page Advertisement [Top]

 What is the difference between Sudo and Su in Linux?


If you are a Linux user, you have probably seen references to both sudo and su. Articles here about How-To Geek and elsewhere instruct Ubuntu users to use sudo and other Linux distribution users to use su, but what's the difference?

Sudo and su are two different ways to get root privileges. Each function is different, and different Linux distributions use different configurations by default.

The root user

Both su and sudo are used to run command permissions. The root user basically corresponds to the administrator user on Windows - the root user has maximum permissions and can do anything with the system. Regular users on Linux run with reduced permissions - for example, they can not install software or write to system directories.

To do something that requires these permissions, you must obtain them with su or sudo.

Sudo mot

The su command switches to the super user - or root user - when you run it without additional options. You must enter the root account password. However, this is not all the su command does - you can use it to switch to any user account. If you run the su bob command, you will be prompted to enter Bob's password and the shell will switch to Bob's user account.

After executing commands in the root shell, enter exit to leave the root shell and return to restricted mode.

Sudo runs a single command with root privileges. When you execute the sudo command , the system asks you for the password of your current user account before executing the root user command . By default, Ubuntu remembers the password for fifteen minutes and will not ask for a password again until the fifteen minutes are up.

This is an important difference between su and sudo. Su switches you to the root user account and requires the password of the root account. Sudo executes a single command with root privileges - it does not switch to the root user or require a separate root user password.

Ubuntu vs. Other Linux distributions

The su command is the traditional way to obtain root permissions on Linux. The sudo command has been around for a long time, but Ubuntu was the first popular Linux distribution that only went as sudo. When you install Ubuntu, the default root account is created, but no password is assigned to it. You can not log in as root until you assign a password to your root account.

There are several benefits to using sudoi instead of su as standard. Ubuntu users only need to enter and remember a single password, while Fedora and other distributions require you to create separate root and user account passwords during installation.

Another advantage is that it discourages users from logging in as a root user - or using su to get a root shell - and keeping the root shell open to perform their normal work. Running fewer commands when root increases security and prevents unintentional system-wide changes.

Distributions based on Ubuntu, including Linux Mint, also use sudo instead of su by default.

A few tricks

Linux is flexible, so it does not require much work to make su work in the same way as sudo - or vice versa.

To run a single command that is rooted with su, run the following command:

on -c 'command'

This is similar to running a command with sudo, but you will need the root account password instead of your current user account password.

To get a complete, interactive root shell with sudo, run sudo -i.

You must enter the password of your current user account instead of the root account password.

Activate the root user in Ubuntu

To activate the root user account on Ubuntu, use the following command to enter a password for it. Remember that Ubuntu recommends against this.

sudo passwd root

Sudo prompts you for the current user account password before you can enter a new password. Use your new password to log in as root from a terminal login prompt or with the su command. You should never run a full graphical environment as a root user - this is a very bad security practice and many programs will refuse to work.

Add users to the Sudoers file

Only administrator accounts in Ubuntu can run commands with sudo. You can change a user account type from the user account configuration window.

Ubuntu automatically designates the user account created during installation as an administrator account.

If you are using another Linux distribution, you can allow the user to use sudo by running the visudo command with root privileges (so run su first or use su-c ).

Add the following line to the file by replacing that user with the name of the user account:

uses ALL = (ALL: ALL) ALL

press Ctrl-X and then Y to save the file. You may also be able to add a user to a group specified in the file. Users in the groups specified in the file will automatically have sudo privileges.

Graphic versions of Su

Linux also supports graphical versions of su, which ask for your password in a graphical environment. For example, you can run the following command to get a graphical password prompt and run the Nautilus file manager with root permissions. press Alt-F2 to run the command from a graphical run dialog without starting a terminal.

gksu nautilus

The gksu command also has a few other tricks up its sleeve - it preserves the current desktop settings so that graphical programs do not look out of place when you start them as another user. Programs like gksu are the preferred way to start graphical applications with root privileges.

Gksu uses either a su- or sudo-based backend, depending on the Linux distribution you are using.


You should now be prepared to face both su and sudo! You will encounter both if you use different Linux distributions.

No comments:

Post a Comment

Bottom Ad [Post Page]