What does su do in Linux, and learn how to use it?


The Unix/Linux su (Replace Consumer) command lets in customers to turn out to be different customers. This command used to be idea to escalate privileges through turning into a privileged consumer; due to this fact, the default consumer is the foundation if no consumer is specified.

By way of executing the su command, you’ll turn out to be root or transfer to another consumer. This educational explains all su usages and the variations with the sudo command.

As stated in the past, should you execute the su command with out a consumer, you are going to turn out to be root through default, as proven within the screenshot beneath.

If you happen to execute the su command adopted through a consumer, you’ll turn out to be that consumer. Naturally, if you’re root whilst you execute su, you gained’t be asked to kind the consumer’s password.

As you’ll see within the instance above, the consumer modified from root to the required consumer linuxhint. But, the present listing stays. You’ll be able to enforce the -l flag to modify the present listing for the objective consumer’s house listing, robotically shifting you from the present listing to the consumer’s house.

When imposing the -l flag, no longer simplest the present listing adjustments. Different options of this flag are:

  • Surroundings variables are cleared aside from the TERM variable for terminal dealing with and whitelisted variables.
  • So much surroundings variables USER, LOGNAME, HOME, SHELL, and PATH.
  • Turns the shell right into a login shell.
  • Adjustments the present listing for the objective consumer’s house.

Differently to breed the similar habits is to interchange the -l flag for only a hyphen (), as proven beneath.

As you’ll see, the consumer modified and in addition the present listing.

The su command can be utilized to run instructions as every other consumer. As proven within the examples beneath, including the -c (Command) flag lets you execute instructions with privileges with out becoming the foundation.

First, let’s see what occurs if we attempt to learn the content material of the foundation listing with out being root:

As you’ll see, the consumer has no permissions to learn the foundation listing. As proven beneath, this can also be achieved with the su command with the -c (Command) flag.

As you notice within the syntax, you wish to have to invoke the su command with the -c flag, adopted through the instructions you need to run between citation marks and adopted through the consumer you need to run the command as, on this case, the foundation consumer.

The runuser command:

There’s an alternate for the su command named runuser. The adaptation between those two instructions is that runuser can simplest be utilized by the foundation. The runuser command doesn’t request a password, and it has a special PAM (Linux Pluggable Authentication Modules) configuration.

As chances are you’ll know, operating browsers as root is forbidden, a nasty apply; your machine will have to save you you from doing that.

In case you are root and you need to release an software unsafe as root, you’ll use each the su command, adopted through the -c flag as defined in the past, or the runuser command proven within the instance beneath, adopted through the -u flag, the consumer you need to run the command as, and the command you need to be completed.

runuser -u linuxhint firefox

The sudo command:

The sudo command is probably the most used choice to run instructions as a privileged consumer. This is a restricted solution to get privileges. When the usage of sudo, you gained’t turn out to be root, however you are going to get permission to execute a selected command.

When the usage of the in the past defined su command, you wish to have to fill within the goal consumer password. When the usage of sudo, as a substitute of typing the objective consumer password, you wish to have to kind the present consumer password; if the consumer is within the sudoers workforce, he’s going to be capable of run the command; if the consumer isn’t within the sudoers workforce, he gained’t be ready.

Operating a command as sudo is lovely easy; simply kind sudo ahead of the command as proven beneath.

For a consumer so that you could run instructions with sudo, you wish to have so as to add him to the sudoers workforce. So as to add a consumer to the sudoers workforce, run the next command.

Now the consumer can run instructions requiring privileges through typing sudo.


The su, runuser, and sudo instructions are simple to enforce and are a few of the most simple Linux instructions any consumer will have to know. Finding out learn how to use those instructions will build up the protection from the consumer facet (Essentially the most inclined). The sudo prefix for privileged instructions is the most efficient choice to stay your machine protected. Some Linux distributions robotically disable the foundation login, leaving sudo because the default way.

I’m hoping this educational is appearing what the command su does and learn how to enforce it used to be helpful. Stay following this weblog for extra Linux guidelines and tutorials.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More