sudo Command in Linux with 12 Example Usage

Linux sudo command allows you to run commands with other user privileges. This command is similar to "Run as" in Windows-based operating systems. In this article, we will see sudo Command in Linux with 12 Example Usage. Click Here If you are interested in knowing the Top 20 Linux Commands for Beginners.

sudo stands for “super user do!”. This command prompts for the password of the current user. The sudo command identifies an authorized user by referencing /etc/sudoers that the system administrator configures. Remember not to edit /etc/sudoers file directly instead use "visudo" command. You can check the "sudoers" file by using the below command:

sudo less /etc/sudoers

(1) List privileges

sudo -l

(2) To restart system immediately

sudo shutdown -r now

(3) To display version number of sudo

sudo -v

(4) To run sudo command in background

sudo -b <command>

(5) To change password of user

sudo passwd <username>

(6) To read files which can be read only by admin

sudo less <file-path>

(7) To run program as admin

sudo ./ 

(8) To run program as another user or group

Below is the command run by user 'alice':

sudo -u alice 

(9) Add user account

sudo useradd <username>

(10) Add user account with an encrypted home directory

For this, first, we need to install the ecryptfs-utils package,

sudo apt install ecryptfs-utils

and then use the --encrypt-home command to encrypt the home directory. You need to add other details for the creation of the user.

sudo useradd --encrypt-home <username> 

The first time when 'testuser' logs in, below command need to use to generate passphrase and user need to store passphrase in a secure place.


(11) To update the system

sudo apt-get update

(12) Display Help of sudo command

sudo --help


This article covers sudo command usage in great details so that you can use it easily. If I have missed any command, write in a comment box below.

Subscribe us to receive more such articles updates in your email.

If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!

Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *