26. chmod command - muneeb-mbytes/linux_course GitHub Wiki

Purpose of chmod command

In Linux, access to the files is controlled by the operating system using file permissions, attributes, and ownership. Understanding the Linux file system permissions model allows you to restrict access to files and directories only to authorized users and processes and make your system more secure.

Each file is owned by a particular user and a group and assigned with permission access rights for three different classes of users:

1.The file owner. 2.The group members. 3.Others (everybody else). There are three file permissions types that apply to each user class and allows you to specify .

1.Read permission-

For the file , the read permission means the user can open the file in text editor . For the directory , the user can list files inside the directory with ls commands .

2.Write permission - The file can be changed or modified. The directory’s contents can be altered. The user can create new files, delete existing files, move files and rename it also.

3.The execute permission -

The file can be executed. The directory can be entered using the "cd" command. Command to check the file permission -

_ls -l filename.txt _

Permission number-

File permission can be represented either in numeric form or in symbolic form .

The permission number can consist of three or four digits, ranging from 0 to 7. When 3 digits number is used, the first digit represents the permissions of the file’s owner, the second one the file’s group and the last one all other users. The write, read, and execute permissions have the following number value:

  1. r (read) = 4

  2. w (write) = 2

  3. x (execute) = 1

  4. no permissions = 0

The permissions digit of a specific user class is the sum of the values of the permissions for that class. Each digit of the permissions number may be a sum of 4, 2, 1 and 0:

0 (0+0+0) – No permission.

1 (0+0+1) – Only execute permission.

2 (0+2+0) – Only write permission.

3 (0+2+1) – Write and execute permissions.

4 (4+0+0) – Only read permission.

5 (4+0+1) – Read and execute permission.

6 (4+2+0) – Read and write permissions.

7 (4+2+1) – Read, write, and execute permission.

The Figure.1. shows how to make the directory readable, writable and executable with permission.

Untitled Diagram-Page-11 drawio (2)

                                Figure.1. Usage of chmod 777 command

GIF.1 shows the whole process from sourcing scripting file till the output.

ch

                                           GIF.1. chmod 777 output GIF 

Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/chmod_command/chmod.csh


777 permission number -

Owner: rwx=4+2+1=7 Group: r-x=4+0+1=5 Others: r-x=0+0+0=0 Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk. Any user on the system will be able to create, delete or modify files in that directory.

Syntax : chmod 777 dir_name

chmod 777 is the command , you’ll use within the Terminal to make a file or folder accessible to everyone.


chmod --help

This command display more info regardinjg chmod command.