Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Linux IntroductionChapter 4. User, Group and Permission

sudo (Run Command with Superuser Privileges)

sudo (Run Command with Superuser Privileges)

Executing Commands with Superuser Privileges

What is sudo?

The sudo (SuperUser DO) command enables users to run programs with the security privileges of the superuser. Normal users don't have execution permission for some commands, for example, installing a new library.

Logging into the system as the superuser frequently may increase security risks such as password breaches. By using the sudo command, you can execute those commands without switching to the superuser.

Who can run the sudo command? – sudoers

Not all users can execute the sudo command. The users who can execute the sudo command have to be members of the sudo group in Ubuntu OS. For CentOS, wheel group members can execute the sudo command. As the users in the sudo or wheel group can act as the superuser, you can manage system administrator users of a server by editing users of the groups. On Ubuntu, you can also use the admin group instead of the sudo group.

IdeaNote: Add users to sudo or wheel group

To give users permission to run the sudo command, include the users in the sudo group (on Ubuntu OS) or wheel group (on CentOS) by running the usermod or gpasswd command. You need to be careful because the order of arguments is different between the two commands. In usermod, you need to specify the group first while you need to specify the user first in gpasswd. The details of usermod and gpasswd will be explained later. Here are example commands.

Example for Ubuntu OS

Command Line - INPUT
sudo usermod -aG sudo user_a

or

Command Line - INPUT
sudo gpasswd -a user_a sudo

Example for CentOS

Command Line - INPUT
sudo usermod -aG wheel user_a

or

Command Line - INPUT
sudo gpasswd -a user_a wheel

To add users to the sudo group or wheel group, you need to create the users first. To create new users, check Useradd (Add User).

IdeaTips: Sudoers and visudo command

The configuration file for sudo is /etc/sudoers. You can check the document using the sudo cat /etc/sudoers command; however, when you edit the file, you need to use the sudo visudo command. The visudo command performs a format check of the file before you save it.

Run the following command to check the /etc/sudoers file.

Command Line - INPUT
sudo visudo

This is an example of Ubuntu OS (20.04 LTS) on AWS Lightsail. The command opens the file with the GNU nano text editor in this case. GNU nano is a built-in text editor for Unix-like computing systems. Key commands to operate the file are displayed at the bottom. "^" means the Ctrl key. For example, press the Ctrl + x key to exit.

Linux visudo command

You can see the following line in the file. % means group. This line defines that members of the sudo group can execute any commands.

%sudo   ALL=(ALL:ALL) ALL

In CentOS, the descriptions of the /etc/sudoers file are different.

This is an example of Cent OS 7 on AWS Lightsail. The sudo visudo command opens the /etc/sudoers file with the Vim editor. When you go to the bottom of the section using the G (shift + g) key, you can see the descriptions similar to the ones in Ubuntu OS; however, there are no descriptions for the sudo group. Instead, you can see the wheel group in the file.

Linux CentOS wheel group

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Enabling Social Login with GitHub in Django Allauth

Django Allauth (5) – Social Login with GitHub

Configuring Email Verification via Gmail with Django Allauth

Django Allauth (4) – Email Verification via Gmail

Introduction to Django Allauth

Django Allauth (1) – Introduction

Enabling Social Login with GitHub in Django Allauth

Django Allauth (5) – Social Login with GitHub

Configuring Email Verification via Gmail with Django Allauth

Django Allauth (4) – Email Verification via Gmail

Introduction to Django Allauth

Django Allauth (1) – Introduction

Tags:

Superuser

Normal User

Sudo

Linux Introduction
Course Content

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server