Linux Sudo command explained |

The Linux terminal is full of useful commands, but none is as important as the sudo command. Allows you to run commands as any other user, with root being the default user.

In this article we will look at the sudo command, how it works and when you can use it to your advantage.

Also read : How do I rename a file under Linux?

Although the sudo package is pre-installed on most Linux distributions, if you get the error message sudo command not found, you can install it with a simple command.

  • Ubuntu and Debian: apt install sudo
  • CentOS and Fedora : yum install sudo

To use the sudo command, add the desired user to the sudoers group. The command reads the /etc/sudoers file to determine if the calling user has sudo access. When you use this command for the first time in a session, you will also be asked to enter a password.

You can read this article to know more.

Also read : How can I check the list of Linux users?

The basic syntax of the sudo command is as follows.

sudo flagship

Note that there are many flags you can use with sudo to customize the behavior, but it is most commonly used in its simplest form.

Password expiry time

By default, the command asks you for the password again after five minutes of inactivity. If you want to change this time limit, follow these steps to edit the send file.

Step 1; Enter the following command to edit the rudder file.


Step two: Add a line and change the number to whatever you want the delay to be in minutes.

Default timetamp_timeout=10

If you want to change the time limit for a specific user, use the following syntax.

Default: username timestamp_timeout=10

Also read : How do I change the password under Linux?

Sudo can execute commands not only as root, but also as any other user with the -u option.

sudo-u eculid whoami

Also read : The Linux Chown team explains

With sudo, you can try to redirect the output of the command to a file. However, if you try to run a command without write permissions on this file, you will get an error message saying you do not have permission.

test sudo echo > /root/file.txt

This is because the output is redirected by the user under whom you are running the command, not by the sudo command.

A solution to this problem is to invoke the new shell as root with this command.

sudo sceptre

So a redirect command would look something like this.

sudo sh -c echo test > /root/file.txt

The second option is to pass the output of the command to the tee command like a normal user.

echo test | sudo tee /root/file.txt

Also read : How do you stop Linux from the command line?

The one who writes/cuts/films/owns all the technology, and when he’s not around, switches to virtual machine races. You can contact Yadullah at [email protected], or follow him on Instagram or Twitter.

frequently asked questions

Using the Sudo command

The Linux Ship Team

What does Sudo do?

Vicki Sudo.

Related Tags:

sudo command in linuxsudo command in linux tutorialsudo commands listsudo command in linux with examplessudo command in unixsudo su command in linux,People also search for,Feedback,sudo command in linux,sudo command in linux tutorial,sudo commands list,sudo command in linux with examples,sudo command in unix,sudo su command in linux,sudo command ubuntu,sudo command not found

Leave a Reply

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