Basic of Linux

Basic of Linux

·

3 min read

Linux -2

Understanding Linux file permissions (how to find them, read them, and change them) is an important part of maintaining and securing your systems.

Change the access permissions of a file

There are three options for permission groups available to you in Linux. These are

  • owners: these permissions will only apply to owners and will not affect other groups.

  • groups: you can assign a group of users specific permissions, which will only impact users within the group.

  • all users: these permissions will apply to all users, and as a result, they present the greatest security risk and should be assigned with caution.

u

user

g

group

o

others

a

all

Linux file permission falls into three categories:

  • Read (r): allow users to open and read the file only. Users can’t modify the file.

  • Write (w): the user can modify (edit, delete) the file and save it.

  • Execute (x): allows the user to run an executable script

r

Read

w

Write

x

Execute

-

No permission

The first column here indicates the permission for the particular file/folder.

If the permission starts with “ “, it indicates that it is a file*.*

Whereas, permissions starting with “d“ indicate it is a directory*.*

Then, every three characters in the permission column indicate the permissions set for various owners in the order of owner, group and others respectively.

Changing file/directory permissions in Linux Using ‘chmod’ command

syntax: chmod permissions filename

There are two ways to change the permission:

  1. Absolute(numeric) mode

  2. Symbolic mode

Absolute mode

In this mode, file permissions are not represented as characters but as a three-digit octal number*.*

  • 0 = No Permission

  • 1 = Execute

  • 2 = Write

  • 4 = Read

Basically, you add up the numbers depending on the level of permission you want to give.

Number

Permission

Symbol

0

No permission

---

1

Execute

--x

2

Write

-w-

3

Execute + Write

-wx

4

Read

r--

5

Read + Execute

r-x

6

Read + Write

rw-

7

Read + Write + Execute

rwx

Refer to a simple example here…

Symbolic mode

Operator 

Description

+

Adds permission to a file/directory

-

Removes the permission

=

Sets the permission and overrides the permissions set earlier

In this mode, we can simply change the permission by

chmod (user)(operator)(permission) [filename]

Refer to this simple example…

It can be well understood that ‘o-w’ here indicates removing the write permission from other user groups.

chmod u=rwx,g=rwx,o=rwx [file_name]

chmod 644 test.txt

chown [user_name] [file_name]

chgrp [group_name] [file_name]

Thank you for reading !!