Day 03 DevOps: Learn Linux Commands for System, User Management, and File Permissions

Prashant GohelPrashant Gohel
9 min read

Linux System-Level Commands, User Management, and File Permissions

This document covers essential Linux commands for system administration, user and group management, file permissions, compression, and file transfer. These commands are fundamental for DevOps engineers and system administrators.


Day 03: Users and File Management


System-Level Commands in Linux (for DevOps & Admin Work)

1. uname – System Information

  • Displays the OS name you're using.

  • Common outputs:

    • Linux (on Ubuntu, RedHat, etc.)

    • Darwin (on macOS)

2. uptime – System Running Time

  • Shows how long the system has been running, how many users are connected, and the system load average.

  • Example: 10:41:09 up 9 min, 1 user, load average: 0.06, 0.07, 0.01

3. date – Current Date & Time

  • Outputs the current date and time of your system (UTC by default).

4. who vs whoami

CommandDescription
whoShows all users who have logged into the system (current & past)
whoamiReturns the username of the current user
  • If you want to know which user has logged in when and their activities, execute the who command.

  • If you want to know which user is currently logged in to the system, execute the whoami command.

Interview Tip: Q: What's the difference between who and whoami?

Ans: who shows a list of users (current and past logins with activity details), while whoami shows only the current active user.

5. which – Locate Executables

which bash
which cp
which java
  • Shows the full path of an executable being used by the system.

  • Helps debug issues when wrong versions or paths are involved.

6. id – User and Group IDs

  • Displays UID (User ID) and GID (Group ID) of the current user.

  • Useful when managing permissions and multiple users/groups on a system.

7. sudo – Super User Privileges

  • sudo (SuperUser Do) allows a non-root user to run commands with administrative privileges.

  • What is sudo?

    • It's a group, typically containing system administrators or users allowed to perform root-level tasks.

    • You can check if your user is in this group by executing the id command.

  • Analogy: Imagine Linux as a house:

    • The Root user (Dad) owns everything.

    • You (Ubuntu user) need permission to touch certain files.

    • sudo is your way of temporarily getting Dad’s approval.

  • Examples:

sudo rm file.txt          # Deletes a file as root
sudo shutdown             # Shuts down the system
sudo apt-get install xyz  # Installs software with root rights
```bash
id                       # Check current user groups
cat /etc/passwd          # List all user accounts

8. shutdown & reboot – Power Management

sudo shutdown
sudo reboot
  • Requires root permission (sudo).

  • Used in cloud environments (e.g., EC2 instances) and local Linux systems.

9. apt – Package Management on Debian/Ubuntu

  • A command-line package manager for searching, managing, and querying information about packages.

  • Install Docker Example:

    1. sudo apt install docker.io

      • Initially, this might return "Permission denied" if not run with sudo.

      • Even with sudo, if packages are not updated, it might fail to find or install dependencies.

    2. sudo apt-get update

      • This command updates the list of available packages and their dependencies. Always run this before installing a new package.
    3. sudo apt-get install docker.io

      • After updating, this command will download from the internet and install Docker.
  • Tip: Instead of typing commands repeatedly, you can search past commands by pressing Ctrl + R and typing a keyword.

sudo apt remove docker.io # To remove Docker
which docker              # Find Docker path

10. Command History Search (Bonus Tip)

  • Ctrl + R: Press Ctrl + R and type a keyword to search previously used commands from your history.
ManagerFor Distribution
yumCentOS
dnfFedora
pacmanArch Linux
portageChromeOS
rpmRed Hat Enterprise

Summary Table: System-Level Commands

CommandPurpose
unameShows system OS name
uptimeHow long the system is running
dateShows current date & time
who / whoamiList all vs current user
whichLocate path of executables
idShow user and group IDs
sudoExecute commands as root
shutdownShut Down System
rebootRestart System
aptInstall/Remove packages
Ctrl + RSearch previous commands
yum, dnf, etc.Other Linux distros' package managers

---

Linux User and Group Management (for DevOps)

One of the key reasons for Linux’s widespread use in enterprise and server environments is its robust user and group management system. It allows administrators to manage access, organize teams, and control system permissions securely and efficiently.

1. Why User & Group Management?

  • In companies, there are multiple users: DevOps engineers, testers, developers, admins, etc.

  • Linux helps organize users into logical groups for access control.

  • This is crucial for security, collaboration, and permission management.

2. How to Create a User

sudo useradd -m jethalal
  • -m: Creates a home directory for the user (e.g., /home/jethalal).

  • sudo: Required because user creation needs superuser privileges.

  • Note: You can check the current user using: whoami

3. Set a Password for the User

sudo passwd jethalal
  • Prompts you to set a login password for the new user.

4. Switch Between Users

su jethalal
  • su means "switch user", and it logs you in as jethalal.
exit

5. View User Information

cat /etc/passwd
  • Lists all the users on the system.
id
  • Displays the user ID (UID) and group ID (GID) of the currently logged-in user.

6. Delete a User

sudo userdel jethalal
sudo userdel -r jethalal # -r removes the user's home directory and mail spool

Group Management

Groups help manage permissions and roles. For example, DevOps team, QA team, etc.

7. Add New Users (Example)

sudo useradd devops1
sudo useradd devops2
sudo useradd tester1
sudo useradd tester2
sudo useradd tester3

8. Create Groups

sudo groupadd devops
sudo groupadd testers

9. View Users and Groups

cat /etc/passwd   # List all users
cat /etc/group    # List all groups

10. Add Users to Groups

sudo gpasswd -a devops1 devops
sudo gpasswd -a devops2 devops
```bash
sudo gpasswd -M tester1,tester2,tester3 testers
  • -M: Specify multiple members to add to a group in one go.

11. Delete a Group

sudo groupdel testers

Summary Table: User and Group Management

CommandPurpose
useradd -m usernameAdd a new user with a home directory
passwd usernameSet password for the user
su username / exitSwitch to another user / go back
cat /etc/passwdList all users
cat /etc/groupList all groups
userdel usernameDelete a user
groupadd groupnameCreate a new group
gpasswd -a user groupAdd a user to a group
gpasswd -M u1,u2 groupAdd multiple users to a group
groupdel groupnameDelete a group

🧠 Interview Tip: Q: What is the purpose of user groups in Linux?

A: Groups help manage permissions collectively. Instead of assigning permissions user-by-user, we assign them to groups and add users to those groups. It simplifies permission management in multi-user systems.


File Permission Commands in Linux

Why are File Permissions Important?

In a multi-user environment like Linux, file permissions ensure that only authorized users can read, write, or execute specific files and directories. This is crucial for security, especially in companies where sensitive data should be protected from unauthorized access.

To control permissions, Linux uses users and groups:

  • Owner (User): The person who created the file.

  • Group: A set of users who can have shared permissions.

  • Others: Everyone else.

🔍 Viewing File Permissions

To check the permissions of files and folders:

ls -l

Example output:

drwxrwxr-x  2 ubuntu ubuntu 4096 Jun 21  linux_for_devops
-rw-rw-r--  1 ubuntu ubuntu    0 Jun 21  devops-file.txt

Explanation:

  • First character:

    • d = directory

    • - = file

  • Next 9 characters (broken into 3 sets of 3): rwx rwx r-x

    • First = permissions for owner

    • Second = permissions for group

    • Third = permissions for others

  • Each position:

    • r = read

    • w = write

    • x = execute

    • - = no permission

Permission Values Table

PermissionBinaryOctal
---0000
--x0011
-w-0102
-wx0113
r--1004
r-x1015
rw-1106
rwx1117

Changing File/Directory Permissions

chmod – Change File Mode (permissions)

chmod

Examples:

chmod 777 cloud            # Gives rwxrwxrwx to the directory
chmod 664 devops-file.txt # Gives rw-rw-r-- to the file

File Ownership Commands

chown – Change File Owner

sudo chown jethalal devops-file.txt

umask – Default Permission Setting

  • umask defines the default permission mask for new files and directories.

  • The default is usually 0002, meaning:

    • New files get 664 (rw-rw-r--) permissions.

    • New directories get 775 (rwxrwxr-x) permissions.

  • You can check the current umask with: umask


Compression Commands in Linux

Compression helps reduce the size of files or directories, making them easier to store and transfer.

Install Zip Utility

sudo apt install zip

Create a ZIP File

zip ldf.zip linux_for_devops
  • Compresses the folder linux_for_devops into a ZIP file named ldf.zip.

Extract a ZIP File

unzip ldf.zip

Gzip and Gunzip

Used for compressing individual files.

gzip filename.txt    # Compresses to filename.txt.gz
gunzip filename.txt.gz # Decompresses to filename.txt

Tar with Compression (Most Common for Linux)

🔸 Compress a Directory

tar -cvzf cloud.tar.gz cloud
  • c – create archive

  • v – verbose (shows progress)

  • z – compress using gzip

  • f – specify the file name

🔸 Extract the Tar File

tar -xvzf cloud.tar.gz
  • x – extract files from archive

  • v – verbose

  • z – unzip

  • f – specify the file name


File Transfer Commands (Local to Remote – EC2)

When working with servers (like AWS EC2), you often need to transfer files from your local machine to the remote server.

scp – Secure Copy

Used to copy files from local → remote, using a .pem key.

scp -i /path/to/key.pem /local/file.txt user@remote_ip:/destination_path

Example:

scp -i ~/keys/linux-key.pem hello.txt ubuntu@ec2-13-233-22-50.ap-south-1.compute.amazonaws.com:/home/ubuntu/

rsync – Remote Sync

More advanced and efficient than scp, especially for syncing folders.

rsync -e "ssh -i /path/to/key.pem" -avz /local/folder/ user@remote_ip:/remote/folder/
  • -a – archive mode (preserves permissions, etc.)

  • -v – verbose output

  • -z – compress during transfer

Example:

rsync -e "ssh -i ~/keys/linux-key.pem" -avz ./project/ ubuntu@ec2-13-233-22-50.ap-south-1.compute.amazonaws.com:/home/ubuntu/
0
Subscribe to my newsletter

Read articles from Prashant Gohel directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prashant Gohel
Prashant Gohel

DevOps & Cloud Enthusiast | Exploring Linux, AWS, CI/CD & Automation | Sharing hands-on notes, tips, and real-world learning as I grow into a DevOps Engineer