chmod Command In Linux | How to Change Permission In Linux | Linux Basic Commands | SN Linux

Published: 02 November 2024
on channel: SN Linux
52
6

In this video we will learn about chmod Command In Linux | How to Change Permission In Linux | Linux Basic Commands | SN Linux

The chmod command in Unix and Linux systems is used to change the file mode bits of a file or directory, which determines the permissions granted to users. Understanding chmod is crucial for managing file access and security. Here’s a detailed explanation:


File Permissions Overview
Each file and directory has three types of permissions:

Read (r): Permission to read the file or list the directory.
Write (w): Permission to modify the file or add/remove files in the directory.
Execute (x): Permission to execute the file (if it's a program or script) or access the directory.
These permissions are set for three different categories of users:

Owner (u): The user who owns the file.
Group (g): The group that the file belongs to.
Others (o): All other users.
Using chmod
The chmod command can be used in two primary ways: symbolic mode and numeric (octal) mode.

1. Symbolic Mode
In symbolic mode, you specify the category of users and the permissions you want to change using letters.

Syntax:

bash
Copy code
chmod [who][operator][permissions] file
who: u (user), g (group), o (others), a (all)
operator: + (add), - (remove), = (set exactly)
permissions: r (read), w (write), x (execute)
Examples:

Add execute permission for the owner:
bash
Copy code
chmod u+x filename
Remove write permission for the group:
bash
Copy code
chmod g-w filename
Set read permission for others:
bash
Copy code
chmod o=r filename
2. Numeric (Octal) Mode
In numeric mode, you use numbers to set permissions. Each permission corresponds to a number:

Read (r) = 4
Write (w) = 2
Execute (x) = 1
You combine these numbers to set the desired permissions. Each category (owner, group, others) gets its own digit.

Syntax:

bash
Copy code
chmod [permissions] file
Examples:

Set permissions to read and write for the owner, and read for the group and others:

bash
Copy code
chmod 644 filename
Breakdown:

Owner: 6 (4+2 for read and write)
Group: 4 (read)
Others: 4 (read)
Set permissions to read, write, and execute for the owner, and read and execute for group and others:

bash
Copy code
chmod 755 filename
Breakdown:

Owner: 7 (4+2+1 for read, write, and execute)
Group: 5 (4+1 for read and execute)
Others: 5 (4+1 for read and execute)
Recursive Changes
You can also change permissions recursively for directories and their contents using the -R option.

Example:

bash
Copy code
chmod -R 755 directoryname
This command sets the permissions of the directory and all its files and subdirectories.

Special Permissions
There are additional permissions that can be set:

Setuid (s): When set on an executable file, the process runs with the privileges of the file owner.

bash
Copy code
chmod u+s filename
Setgid (s): When set on a directory, files created within inherit the group of the directory.

bash
Copy code
chmod g+s directoryname
Sticky Bit (t): When set on a directory, only the owner can delete or rename files within that directory.

bash
Copy code
chmod +t directoryname
Viewing Permissions
You can view the current permissions of files and directories using the ls -l command. The output will show a string of characters indicating permissions for each category.

The chmod command is a powerful tool for managing file permissions in Unix/Linux systems. By using symbolic or numeric modes, you can tailor access to files and directories based on user needs, enhancing both functionality and security.

Telegram Link:-
https://t.me/SNLlinux

Instagram:-
https://www.instagram.com/sn.linux?ig...

Other Videos:-
Networking Troubleshooting In Linux -    • Networking Troubleshooting In Linux | Linu...  

Fstab File Explained In Linux -    • Fstab File Explained In Linux | Part -24 |...  

How To Monitoring & Manage Logs -    • How To Monitoring & Manage Logs | Part - 2...  

NFS Server & NFS Client Set Up -    • NFS Server & NFS Client Set Up | Part - 23...  

Configure SSH Passwordless Authentication & Using SSH Keygen On Linux -    • Configure SSH Passwordless Authentication ...  

Learn Linux SSH Basics - How to Connect to a Server -    • Learn Linux SSH Basics - How to Connect to...  

How to Assign and Use Static IP Addresses & Dynamic Host Configuration Protocol (DHCP) -    • How to Assign and Use Static IP Addresses ...  

Steps for Network Troubleshooting -    • Steps for Network Troubleshooting | How to...  

How to deploy website from GitHub repository? | How to clone GitHub repository ? -    • How to deploy website from GitHub reposito...  

Adding New Disks, Partitions & Filesystem -    • Adding New Disks, Partitions & Filesystem ...  

How To Check Utilisation Using Top Command -    • Video  

#interviewquestions
#learnlinux
#linuxtutorial
#linuxtips
#linuxlearning
#interviewpreparation

Hi friends,

Here we learn about Linux, Aws, Windows & all other important things about IT Industry. We will provide information about how to enter in this field, how to creck interviews and many things. We will solve all of your queries and provide best information.
So support me by Like, Share & Subscribe my channel.


On this page of the site you can watch the video online chmod Command In Linux | How to Change Permission In Linux | Linux Basic Commands | SN Linux with a duration of hours minute second in good quality, which was uploaded by the user SN Linux 02 November 2024, share the link with friends and acquaintances, this video has already been watched 52 times on youtube and it was liked by 6 viewers. Enjoy your viewing!