Enter your email address below and subscribe to our newsletter

How to Use the Sudo Command in Linux

Share your love

If you are new to Linux operating system, then you missed somany things. Linux is not much popular as compared to Windows and Mac OS, but it is the best OS if you are a server administrator, developer, security admin, or programmer. Now, like Windows, where we need Administrator permission to execute some system-level operations, we have Sudo in Linux. It is one of the most powerful commands and the first commands that you should know before getting started with Linux. So if you are planning to use Linux, you have to learn more about Sudo and its use to manage permissions.

What Is the Sudo Command?

As we already mentioned above, the Sudo command manages permissions for apps and services in Linux. Some system commands need sudo permission to run and make changes to your system. Whenever you see an error like you don’t have permission to run the command, you should use sudo before that command.

Sudo was programmed to allow any user to run a command as if they were the superuser. Sudo command will allow any user to run any command or also restrict any user.

You must provide your password to run the Sudo command. Sudo access must also be granted to your user account. If it doesn’t, you’ll need to edit the sudo configuration file to permit yourself or ask the system administrator if you don’t have it.

Why Do you need Sudo Command?

For security reasons, it is better to restrict access to certain users or parts of the system through suid binaries. It is very easy to create these binaries in Linux. Creating the suid binary is relatively easy too. In Linux, a facility called the Sudo package creates these binaries automatically when you install certain programs.

The first time you run a command as a superuser, the system will prompt for the password. The superuser password is needed so that others can’t change any of the files or directories currently in use.

You can use many different user names for different purposes. When you are a root user, you can run most commands as root. Usually, when you become a normal user, your commands go to the terminal as root. When you become a superuser, your commands appear as an execute command instead of normal command. Most Linux distributions have a Sudo package which allows you to change these commands after installation.

Uses of Sudo Command in Linux

What is great about using the sudo command is that it enables you to configure your computer settings such as your login name, username, and displayed mail address. However, these two are only part of the many that you can do with your username. You can also change your homepage, take a backup of your home directory, disable or enable su, change your username on your terminal, change your wheel group, configure your forwarding DNS, and connect to the internet. In addition, if you need to reset your password, you can simply reboot your machine and use the new password.

If you are new to Linux and just playing around with it then you won’t need to worry about this thing. But if you are going to play with system files then you should have sudo permission.

Here are some important sudo options and its function in Linux:

sudo adduser username

sudo adduser username

As a superuser, you can create or remove the existing user on your system. Replace adduser with your desired username. You can also add a new user to the sudo group using this command.

Try to run a command with sudo permission and see if it is working or not. Like: su geniusgeeks

Try to access root directory files using this command – sudo ls -la /root

usermod -aG sudo newuser

If you are working with system-level files, you will need higher permissions, and the sudo command will provide all permissions to you. Normal user accounts are restricted from performing sensitive tasks, such as accessing /root directory, because it contains all system files, including DNS, security, and other important files.

sudo -h

For a beginner, we recommend this sudo -h command first. This command will list down all the information related to the sudo command and its usage. It will guide you to use the sudo command as well.

sudo -u username

If you want to execute the sudo command for any user then you can use this sudo -u username command. Here it will allow temporary sudo access to that use.

sudo -k

This command will erase your timestamp details and old credentials. So once you run this command, you have to enter all the passwords again.

sudo -v

Just like the above command, this command will update your timestamp.

sudo -l

If you want to see which commands you can use and which not then type this command in the terminal.

sudo l command

How to Install Sudo

If your system doesn’t have a sudo feature then you have to install it manually. Most of the Linux distribution has this command by default. If you see sudo command not found an error in the terminal while executing any command then follow these steps to install sudo on your system.

Step 1: Open a terminal on your Linux and enter this command in the command box:

apt-get install sudo

For CentOS or Fedora, the command will be:

yum install sudo

How to Delete a User using the sudo command

You can also delete any user using the sudo command in Linux as we mentioned above. Here are the steps for that:

Step 1: Open your terminal in Linux and then type this command.

sudo deluser username
sudo userdel username (Fedora / CentOS)

Replace the username with the username that you want to delete.

Related Posts:

Final Words

We hope you liked our detailed guide on the Linux Sudo command. If you want to learn more about Sudo permission and Sudo command then stay tuned with our Linux tutorials and you’ll never be disappointed.

Share your love
Rahul Patel
Rahul Patel

Rahul is a blogger and a tech geek. By reviewing the latest technology and finding the solution of pesky errors, he feels immense pleasure. Driven by his innate interest in blogging, he adapted blogging as a full-time profession 4 years ago.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!