sudo Command in Linux with 12 Example Usage
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/sudo-command.jpg?resize=720%2C340&ssl=1)
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
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/sudoers-1.jpg?resize=1024%2C574)
(1) List privileges
sudo -l
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/sudo-l.jpg?resize=1024%2C114)
(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 ./script.sh
(8) To run program as another user or group
Below is the command run by user 'alice':
sudo -u alice script.sh
(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
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/install-ecryptfs-utils.jpg?resize=1024%2C575)
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>
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/testuser.jpg)
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.
ecryptfs-unwrap-passphrase
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/ecrypt-passphrase.jpg)
(11) To update the system
sudo apt-get update
(12) Display Help of sudo command
sudo --
help
![](https://i0.wp.com/allabouttesting.org/wp-content/uploads/2021/05/sudo-help.jpg?resize=1024%2C532)
Conclusion
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.