BEST WAY TO CHANGE DIRECTORY PERMISSIONS IN LINUX

LINUX is a clone of UNIX, a multi-user operating system where multiple users can use it at the same time. When you run an ls command, no file protection information is provided to you since, by default, ‘ls’ just list file names. By using “option” with the “ls” command, you can get more details. All the options start with a ‘-‘.

For example, you can type ls -ls to execute ‘ls’ with the ‘long listing’ option. A particular file is listed within the long format on a separate line. Here is the screenshot of it.

There is a lot of data on those lines:

  • Almost always, the first character is either ‘-‘, which means that it’s a file, or ‘d’, which means it’s a directory.
  • The next nine characters(rw-r-r-) shows the security.
  • The other column shows the owner of the file.
  • The next column displays the file’s group owner.
  • The next column will display the file size in columns.
  • The next column displays the time and date of the last update of the file.
  • The final last column gives the file name.

Linux can also be used without any changes on mainframes and servers. But this poses security issues as crucial data can be compromised, changed or deleted by an unsolicited or malignant person. Linux divides authorization into two levels:

  • Ownership
  • Permission

Start your 30-day FREE TRIAL with CloudInstitute.io to get access to over 200+ courses. Connect with our experts to learn about our IT courses.

1)Ownership of Linux files

There are three types of owners, and provided below are allocated to each file and directory on your LINUX/UNIX system.

User: A user is the file creator. The person who has generated a file becomes its owner by default. Hence, often a user is also called an owner.

Group: A user-group can contain many users. Both users belonging to a community would have the same file access rights.

Other: Any other user who has file access. This individual has not generated a file nor does he belong to a user community that would own the file.

2) Permissions:

In your Linux/Unix system, each file and directory have three permissions specified for all the three owners discussed above.

User: This permission gives you the authority to open read a file. The authorization to read a directory gives you the right to list its contents.

Write: Writing permission gives you the power to change the contents of life. Writing permission for a directory gives you the power to add, delete and rename files stored in the directory. Consider a situation in which you have to write permission to a file but have no permission to write to the directory where the file is stored in the directory. Consider a situation in which you have to write permission to a file but have no permission to write to the directory where the file is stored. You will be able to change the contents of the files, but you won’t be able to rename, transfer or delete a directory file.

Execute: In Windows, an executable program usually has an extension named “.exe” and you cannot run it quickly. In Linux/Unix, unless the execute permission is set, you cannot run a program. You can still be able to see/modify the program code if the execute permission is not set, but do not run it.

Changing file/directory permissions with ‘chmod’ command

We may use the command ‘chmod’ that stands for change mode. Using the command, we can set (read, write, execute) permissions for the user, group and world to a file/directory.

 

Syntax: chmod permissions filename

To change directory permissions for the owner of the file, use the following:

to add permissions chmod +rwx filename

to remove permissions chmod -rwx filename

to allow executable permissions chmod +x filename

to take out write and executable permissions chmod -wx filename

The characters denote

‘r’ =read

‘w’ = write

‘x’ = execute

‘-‘ = no permission

Group owners and others

The command to modify group owner directory permissions is identical, but add a ‘g’ for group or an ‘o’ for users:

chmod g+w filename

chmod g-wx filename

chmod o+w filename

chmod o-rwx filename

There are two ways to use the command: Absolute mode and Symbolic mode.

1.Absolute(numeric) model: File permissions are expressions in this mode, not as characters but as a three digital octal number.

To do this we use numbers instead of ‘r’,’w’,’x’

0= no permission

1= execute

2= write

4= read

Permission numbers are:

0= … (no permission)

1= --x (execute)

2= -w- (write)

3= -wx- (execute+write)

4= r- (read)

5= r-x (read+execute)

6= rw- (read+write)

7= rwx (read+write+execute)

2)Symbolic mode:

You change permission for all three owners in the absolute mode. You may change the permissions of a particular owner in symbolic mode. To change the file permissions, it allows use of mathematical symbol.

+

adds permission to a file

- Remove the permission

= sets the permission and overrides the permissions that are set earlier

The owners are represented as:

u

user/owner

g group

o other

an all

In numbers like 866, we will not be using permissions, but characters like rwxx.

Changing Ownership and Group

The following orders may be used to modify the ownership of a file/directory:

chown user

If you want to change both a user and a group for a file or a directory, use the command:

chown user: group filename

If you only want to change the group’s owner, use the command:

chgrp group_name filename

‘chgrp’ stands for ‘change group’.

In the end, I’ll conclude this topic with the following points:

  • As a multi-user device, Linux uses permission and ownership for stability.
  • On a Linux system, there are three user styles: user, group and other.
  • Linux splits the permission in to read, write and execute permissions denoted by ‘r’,’w’,’x’.
  • You can modify the permissions on a file with the ‘chmod’ command, which can be further split into Absolute and Symbolic mode.
  • The ‘crown’ command will change the ownership of file/directory, using the commands below:
  • Chown user file,or chown user file:group file.
  • The ‘chgrp’ command will modify the filename of the chgrp group ownership group.
  • X-executing a directory means to allow to’enter’ a dir and gain possible access to sub-dirs.

Start your 30-day free trial today.