How to use the Linux sudo command to carry out tasks in another user’s name

The sudo command allows Linux users to have temporary access to sensitive areas of the system. This access is protected by a password and is only applicable for a short time.

What is the Linux sudo command?

Linux sudo is one of the most important Linux commands if you want to install a program or make changes to the system configuration. The command is one of the most basics for most Linux distributions such as Debian or Ubuntu and should never be removed. sudo stands for ‘superuser do’ and allows users with authorisation to run commands for other users. An example of this is a root user, who will not be given complete root rights from the sudo command.

How does the sudo command work?

Linux sudo is used, first and foremost, to protect the system from fake packages or other unwanted processes before they’re installed. If you want to use the command, you simply add it before another command. For example, the command is used to make changes to the system configuration without having root rights or to open individual programs for which you need root rights. To use the command you will need a password which is normally different to the root password. It’s also usually only valid for 15 minutes. The users that are allowed to use the sudo command can be specified in the file /etc/sudoers.

What does the Linux sudo syntax look like?

Linux sudo is always in front of another command. This makes it look as follows:

$ sudo [Command]
shell

This allows users to carry out the command without root rights.

What options does the sudo command have?

There are different options for the Linux sudo command. The most important are:

  • -h: Blends the systax as well as all available options for the sudo command.
  • -k: Ends all current Linux sudo privileges.
  • -l: Opens a list in which all permissions are listed.
  • -V: Shows the current sudo application version.
  • -v: Starts the sudo permission time again. This is usually 15 minutes until the password needs to be reentered.

Linux sudo examples

So that you can see how the command works, here are a few examples:

$ sudo apt-get update
shell

If you didn’t enter the sudo command here, it’s highly likely that the system would return an error message. By using it, you will be asked to enter a password. If this is correct then the command will be executed. However, you must enter the password ‘blind’ because it’s not shown on the screen.

$ sudo -u [Other_Username] ls ./Example
shell

Use this command to list the directory /Example on behalf of another user.

In order to provide you with the best online experience this website uses cookies. By using our website, you agree to our use of cookies. More Info.
Manage cookies