# Basic of Linux

# 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679465483861/3502bde1-b96e-4c9b-9545-fa79db565822.png align="center")

**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.
    

<table><tbody><tr><td colspan="1" rowspan="1"><p>u</p></td><td colspan="1" rowspan="1"><p>user</p></td></tr><tr><td colspan="1" rowspan="1"><p>g</p></td><td colspan="1" rowspan="1"><p>group</p></td></tr><tr><td colspan="1" rowspan="1"><p>o</p></td><td colspan="1" rowspan="1"><p>others</p></td></tr><tr><td colspan="1" rowspan="1"><p>a</p></td><td colspan="1" rowspan="1"><p>all</p></td></tr></tbody></table>

**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
    

<table><tbody><tr><td colspan="1" rowspan="1"><p>r</p></td><td colspan="1" rowspan="1"><p>Read</p></td></tr><tr><td colspan="1" rowspan="1"><p>w</p></td><td colspan="1" rowspan="1"><p>Write</p></td></tr><tr><td colspan="1" rowspan="1"><p>x</p></td><td colspan="1" rowspan="1"><p>Execute</p></td></tr><tr><td colspan="1" rowspan="1"><p>-</p></td><td colspan="1" rowspan="1"><p>No permission</p></td></tr></tbody></table>

*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.*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679464744835/e7f7659b-4534-4209-b3bd-eaf5a6df317b.png align="center")

***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.*

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Number</strong></p></td><td colspan="1" rowspan="1"><p><strong>Permission</strong></p></td><td colspan="1" rowspan="1"><p><strong>Symbol</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p>0</p></td><td colspan="1" rowspan="1"><p>No permission</p></td><td colspan="1" rowspan="1"><p>---</p></td></tr><tr><td colspan="1" rowspan="1"><p>1</p></td><td colspan="1" rowspan="1"><p>Execute</p></td><td colspan="1" rowspan="1"><p>--x</p></td></tr><tr><td colspan="1" rowspan="1"><p>2</p></td><td colspan="1" rowspan="1"><p>Write</p></td><td colspan="1" rowspan="1"><p>-w-</p></td></tr><tr><td colspan="1" rowspan="1"><p>3</p></td><td colspan="1" rowspan="1"><p>Execute + Write</p></td><td colspan="1" rowspan="1"><p>-wx</p></td></tr><tr><td colspan="1" rowspan="1"><p>4</p></td><td colspan="1" rowspan="1"><p>Read</p></td><td colspan="1" rowspan="1"><p>r--</p></td></tr><tr><td colspan="1" rowspan="1"><p>5</p></td><td colspan="1" rowspan="1"><p>Read + Execute</p></td><td colspan="1" rowspan="1"><p>r-x</p></td></tr><tr><td colspan="1" rowspan="1"><p>6</p></td><td colspan="1" rowspan="1"><p>Read + Write</p></td><td colspan="1" rowspan="1"><p>rw-</p></td></tr><tr><td colspan="1" rowspan="1"><p>7</p></td><td colspan="1" rowspan="1"><p>Read + Write + Execute</p></td><td colspan="1" rowspan="1"><p>rwx</p></td></tr></tbody></table>

*Refer to a simple example here…*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679465040166/0556c109-2625-414c-8f08-74677395b5dd.png align="center")

# ***Symbolic mode***

<table><tbody><tr><td colspan="1" rowspan="1"><p>Operator&nbsp;</p></td><td colspan="1" rowspan="1"><p>Description</p></td></tr><tr><td colspan="1" rowspan="1"><p>+</p></td><td colspan="1" rowspan="1"><p>Adds permission to a file/directory</p></td></tr><tr><td colspan="1" rowspan="1"><p>-</p></td><td colspan="1" rowspan="1"><p>Removes the permission</p></td></tr><tr><td colspan="1" rowspan="1"><p>=</p></td><td colspan="1" rowspan="1"><p>Sets the permission and overrides the permissions set earlier</p></td></tr></tbody></table>

In this mode, we can simply change the permission by

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

Refer to this simple example…

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679465329229/cca9a466-50f2-4eb1-8840-3c6ea18b61d8.png align="center")

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 !!
