What Is Sudo Command in Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/what-is-sudo-command-in-linux/
PINTEREST
PINTEREST
INSTAGRAM

sudo or superuser do is a utility used on Linux, BSD and Unix systems that provides the running command with root or Administrator privileges. Not every user needs to have root privileges but in some cases needs to run commands with root privileges. We can use sudo to run some specific or all provided commands and edit files with the root privileges.

sudo Configuration File sudoers

sudo command is configuration is stored /etc/sudoers file. This file can be only viewed and edit with root privileges. We can edit this just with visudo command like below.

sudo Configuration File sudoers
sudo Configuration File sudoers

We can see that there is a different part of sudoers configıration file where default values, user and group privileges are provided.

Configuration Syntax

We can use the following syntax in order to create a sudo configuration about the given user or group.

  • USER is the user who can run the given command on the given host
  • HOSTLIST is the hosts where given commands can be run
  • COMMANDLIST is the commands can be run. Multiple commands can be delimited with the comma.

Specify A User To Run Sudo Command

We can add a user to run a specific command with root privileges. In this example, we will add user ismail to run command visudo with root privileges.

Specify A User To Run Sudo Command
Specify A User To Run Sudo Command

Passwordless Sudo Command

We can provide sudo command to the given user without any password. We will use NOPASSWD configuration like below which will disable password for the user ismail.

List Available Commands

We can list available commands with the -l option which will list currently used root privileged commands the current user can execute.

LEARN MORE  What Does "sudo apt-get update" do?

List Available Commands
List Available Commands

Run Command with Root Privileges

In this example, we will run commands with root privileges by using sudo command. We will run ls command in the /root directory which is completely owned by root and only used by root user.

Edit File with Root Privileges

We also edit files with the root privileges by using sudo command. We will edit the /etc/passwd file with the vim command like below.

Edit File with Root Privileges
Edit File with Root Privileges

Difference Between sudo and su

su command is used to login as root user on the other side sudo command just runs given command as root in the current user sessions. While running sudo the user name will be also logged but with the sudo command just the root user name will be logged. The best way to

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/what-is-sudo-command-in-linux/
PINTEREST
PINTEREST
INSTAGRAM