sudo Linux Command with Examples
sudo Linux Command with Examples
In this tutorial, we will learn sudo Linux command with some examples. In Linux, the password for the root user( sometimes also called superuser) is locked by default. The root user cannot log in to the system. It is not recommended to enable the root account in Linux. sudo stands for substitute user do or superuser do.
In the Terminal, we can use sudo for commands that require the root privileges to run the command. The sudo command would prompt your password to enter. The sudo command is configured and users who can run the command are maintained in the /etc/sudoers file.
sudo Linux Command
Command Format
$ sudo <command_that_requires_root_privilege>
For more information type the following command in the Terminal prompt
$ man sudo_root
The sudo command adds a log entry in the /var/log/auth.log file.
# Run commands
testingdocs@ubuntu:~$ sudo uptime
[sudo] password for testingdocs:
23:47:04 up 36 min, 1 user, load average: 0.81, 0.59, 0.69
View the auth.log file:
testingdocs@ubuntu:~$ tail -f /var/log/auth.log
# Edit a system file example
We need to perform sudo for any administrative tasks in the Terminal, such as installing an application software package, extracting files, editing system files, and copying or moving directories.
$ sudo gedit /etc/profile
In this example, we require sudo access to open and edit the system file /etc/profile. We are adding the Java environment variables to the file.
# Docker commands
We can use the sudo command to elevate the user’s permissions. This is not just for running docker commands; it’s for running any commands that need elevated permissions.
For example to list the Docker images on the local repository.
$ sudo docker images
More Information on the sudo command:
Linux Commands
Linux Basic Commands Tutorial page:
More Information on Ubuntu Linux: