Logo
Overview
Basic Linux commands

Basic Linux commands

July 23, 2020
2 min read

Overview

This guide covers essential Linux commands for user and group management, which are fundamental for system administration and security. Whether you’re managing a single server or multiple systems, these commands will help you maintain user accounts efficiently.

Note

Most of these commands require sudo (superuser) privileges. If you’re not in the sudoers group, ask your system administrator to grant access before proceeding.

User Management

List All Users

Display all user accounts on the system:

Terminal window
cat /etc/passwd

Each line shows: username, password hash, UID, GID, full name, home directory, and login shell.

Add a New User

Create a new user account with a home directory:

Terminal window
sudo adduser username

This command will prompt you to:

  • Set a password
  • Confirm the password
  • Enter user information (name, room number, phone, etc.) — leave blank if not needed

Add User to Sudo Group

Grant administrative privileges to an existing user:

Terminal window
sudo usermod -aG sudo username

The -aG flag means: -a (append) and -G (groups). The user is added to the sudo group without removing from other groups.

Warning (Sudo Access)

Only add trusted users to the sudo group, as they gain root-level access. Always verify before granting sudo privileges.

Delete a User

Remove a user account while keeping their home directory:

Terminal window
sudo deluser username

Delete User and Home Directory

Completely remove a user and all their files:

Terminal window
sudo deluser --remove-home username
Danger (Permanent Deletion)

This command permanently deletes the user’s home directory and all files. There is no undo — ensure you have backups before proceeding.

Group Management

List All Groups

Display all groups on the system:

Terminal window
cat /etc/group

Each line shows: group name, password field, GID, and member list.

Create a New Group

Terminal window
sudo addgroup groupname

Add User to Group

Terminal window
sudo usermod -aG groupname username

Remove User from Group

Terminal window
sudo deluser username groupname

File Permissions and Ownership

Change Group Ownership

Assign a group to a directory and all its contents recursively:

Terminal window
sudo chgrp -R groupname directoryname

The -R flag applies the change recursively to all files and subdirectories.

Tip

For example, to give the www-data group ownership of a web directory:

Terminal window
sudo chgrp -R www-data /var/www/mysite

Change File Ownership

Change both user and group ownership:

Terminal window
sudo chown -R username:groupname directoryname

Example:

Terminal window
sudo chown -R ubuntu:ubuntu /home/ubuntu/myproject

View File Permissions

Terminal window
ls -l filename

Output shows permissions, owner, group, size, date, and filename.

Summary

These fundamental commands are essential for managing users, groups, and permissions in Linux systems. Regular practice will make these operations second nature for system administration tasks.

To make directory read write access to group

sudo chmod g+rwx -R directoryname