Skip to content

Linux Users, Groups, and Sudo Permissions

โ† Back to Linux Commands


User and permission management is a core responsibility of DevOps engineers.
This section explains how Linux handles users, groups, file ownership, and sudo access, which are critical for server security and access control.


sudo โ€“ Getting Root Permissions

sudo allows a normal user to execute commands with root (administrator) privileges.

ll /etc/passwd

Trying to edit system files as a normal user:

vi /etc/passwd    # Read-only, cannot write

Using sudo:

sudo vi /etc/passwd   # Able to write

๐Ÿ“Œ DevOps Tip: Avoid logging in directly as root. Use sudo instead.


Understanding User and Group Permissions

Each file in Linux has: - Owner - Group - Permissions

Example:

[opc@new-k8s etc]$ ll /etc/os-release
-rw-r--r--. 1 root root 452 Sep 30  2020 /etc/os-release

Breakdown: - root โ†’ owner - root โ†’ group - rw-r--r-- โ†’ permissions


Switching Users

sudo su

Switch to another user:

su vignesh

Switch with full environment:

su - vignesh

Creating a User

Ubuntu / Debian Based Systems

By default, useradd creates a user without a home directory.

useradd test

Create user with home directory:

useradd -m test1

Set Password for a User

passwd test

Verify User Creation

cat /etc/passwd

Test: User Installing a Package

sudo yum install tree

โŒ This will fail because the user does not have sudo privileges.


Giving Sudo Permission to a User

To grant sudo access, add the user to the appropriate group.

CentOS / Oracle Linux / RHEL

usermod -aG wheel test

Group name: wheel

Ubuntu / Debian

usermod -aG sudo test

Group name: sudo


Verify Group Membership

id test
cat /etc/group

Test Again: Installing Package

sudo yum install tree

โœ… This will now work because the user has sudo privileges.


Remove User from Group

gpasswd -d test wheel

Delete a User

Delete user without deleting files

userdel test

Delete user along with home directory

userdel -r test

Practice Tasks

  1. Create a new user named devops
  2. Set a password for the user
  3. Try editing /etc/hosts without sudo
  4. Add the user to sudo group
  5. Verify sudo access
  6. Remove the user

๐Ÿง  Quick Quiz โ€” Users & Sudo Permissions

#

Which group gives sudo access to users on Ubuntu systems?


๐Ÿ“ Want More Practice?

To strengthen your understanding and prepare for interviews, try the full 20-question practice quiz based on this chapter:

๐Ÿ‘‰ Start Users & Sudo Permissions Quiz (20 Questions)


๐Ÿš€

Practice Live in Your Browser

Stop reading and start doing! Launch a fully-configured, secure Linux sandbox directly in your browser. Practice commands, debug broken servers, and complete timed challenges with instant task validation.

FREE LAUNCH OFFER Get all premium Linux labs for FREE until July 31st! (No Credit Card Required)

๐Ÿ“ฌ DevopsPilot Weekly โ€” Learn DevOps, Cloud & Gen AI the simple way.
๐Ÿ‘‰ Subscribe here