Beginner’s Guide to Linux: Users, Permissions, File System, and Essential Commands
Linux is a multi-user operating system, which means it can be used by many people at once, each with their own account, permissions, and files. Let’s understand a bit about file system and accounts in linux.
1. Linux Accounts: Who’s Who in Linux
Root User: The root user is the “superuser” of the system, with full control over everything. Imagine it as the “admin” account. The root user can do anything and everything, including adding or deleting other users, changing any file, and installing or removing software.
Regular Users: These are the everyday accounts with more limited permissions. Each regular user can only access their own files and certain parts of the system, making it a more secure way to manage multiple people on one computer.
Service Accounts: These are special accounts created specifically for system services and background processes (like web servers). These accounts don’t allow people to log in, as they’re only for the system’s internal use.
2. Users, Groups & Permissions: The Basics of Access Control
Users: Every individual with access to the system has their own unique user account.
Groups: A group is a collection of users who have similar access needs. For example, there might be an "admin" group for users who need elevated permissions or a "developers" group for coding teams. Users can belong to more than one group.
Permissions: In Linux, every file and folder has permissions that control who can access or modify them. Permissions apply to:
Owner: The user who created the file.
Group: Users in the same group as the owner.
Others: Everyone else on the system.
Permission Types
Read (r): Allows a user to view the contents of a file or list a directory’s contents.
Write (w): Lets a user modify or delete a file or create new files in a directory.
Execute (x): Allows a file to be run as a program or a directory to be accessed.
3. User Management in Practice
Creating Users: To add a new user, you can use the command:
sudo useradd <username>
Or a more user-friendly option:
sudo adduser <username>
Deleting Users: To remove a user, use:
sudo userdel <username>
Setting Passwords: To set or change a password for a user:
sudo passwd <username>
Managing Groups:
Create a new group:
sudo groupadd <groupname>
Add a user to a group:
sudo usermod -aG <groupname> <username>
Remove a user from a group:
sudo gpasswd -d <username> <groupname>
4) File Ownership & Permissions
Every file has an owner, a group, and specific permissions for the owner, group, and others.
To view file permissions and ownership, use:
ls -l <filename>
The first character shows if it’s a directory (
d
) or a file (-
).The next three characters (
rwx
) show the permissions for the owner.The next three (
rwx
) show the permissions for the group.The last three (
rwx
) show the permissions for others.
-Modifying Permissions
Change Ownership: To assign a file’s ownership to a different user or group:
sudo chown <user>:<group> <file> #sudo chown Raunak:Developer abc.txt
Change Permissions:
Symbolic Mode: This mode lets you add (
+
), remove (-
), or set (=
) permissions for the owner (u
), group (g
), others (o
), or all (a
).chmod u+x <file> # Gives execute permission to the owner
Octal Mode: Permissions are represented by numbers:
r = 4
,w = 2
,x = 1
Example:
chmod 755 <filename>
(Owner can read, write, execute; group and others can only read and execute)
—Linux File System
The Linux file system organizes everything in a hierarchical (tree-like) structure, with the root directory (/
) at the top. Here are the main directories:
/ (Root): The top-level directory containing all system files and folders.
/home: Holds individual user directories (
/home/username
)./bin & /sbin: Store essential system binaries (programs) and admin commands.
/etc: Contains system configuration files.
/var: Holds variable data like logs and temporary files.
/tmp: Temporary files.
/usr: User-installed programs and libraries.
/opt: Third-party software.
-File Paths
Absolute Path: A full path starting from
/
, e.g.,/home/user/file.txt
.Relative Path: A path relative to the current directory, e.g.,
../folder
.
-Mount Points
Physical devices (e.g., USB drives) are connected to the file system by "mounting" them to a directory, making them accessible.
—Basic Linux Commands
Now let’s learn some basic commands for getting around and managing files!
1. Introduction to Command Line Interface (CLI)
The command line interface is a text-based way to interact with the computer. A shell (like
bash
orzsh
) interprets your commands and tells the operating system what to do. You access the shell through a terminal program.2. Essential Linux Commands
Directory Operations
ls – Lists directory contents.
cd <directory> – Changes to a different directory.
pwd – Shows the current working directory.
Navigating the File System
cd .. – Goes up one directory level.
cd ~ – Goes to the home directory.
ls -a – Lists all files, including hidden ones.
Working with the File System
Create Folders:
mkdir <foldername>
List Files:
ls
Rename/Move Files:
mv <source> <destination>
Copy Files:
cp <source> <destination>
Remove Files:
rm <filename>
Remove Directories:
rm -r <directory>
Execute Commands as Superuser
sudo: Allows you to execute commands with root privileges.
sudo <command>
- Example:
sudo apt update
updates the package list on a Debian-based system.
- Example:
-Pipes, Redirects, Less, and Grep
Pipes (|
): Connects commands so the output of one command is the input of another.
- Example:
ls | grep <keyword>
Redirection:
>
– Redirects output to a file, overwriting it.echo "Hello" > file.txt #output : Hello (in file.txt) overwriting whatever it was written before
>>
– Redirects output to a file, appending to it.echo "Hello" >> file.txt #output : Hello (in file.txt) appending whatever was written before
<
– Redirects input from a file.wc -l < file.txt #takes input from file.txt and "wc" is used to print count of lines in it
Less: Opens a large file for reading, page by page.
less <filename>
Grep: Searches for specific text patterns within files or command output.
grep "pattern" file.txt
#searches for "pattern" word in file.txt
These are some of the commands to know while starting out learning about linux, you can explore more by yourself.
Some Resources
https://www.youtube.com/watch?v=iwolPf6kN-km (Kunal Kushwaha video on linux)
https://www.linux.com/what-is-linux/
https://www.geeksforgeeks.org/introduction-to-linux-operating-system/