• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

chmod Command in Linux (Managing File Permissions)

Written by Rahul, Updated on December 19, 2020

Linux chmod command is used to change access permissions of files and directories. In this article, you will learn how to change permissions of any file or directory with chmod command. We have already described the Linux file permissions.

Syntax:

chmod [PERMISSIONS] [FILE]...

Role & Permission Types

To understand file permission you must know about Roles and Permission types. There are three types of roles available in Linux systems (User, Group, and Others). Each role has 3 types of permissions (Read, Write, and Execute).

Roles:

  • User (Owner)
  • Group (All group members)
  • Other (All other users

Permissions:

  • Read (r) – Member can read the file content or List files in a directory
  • Write (w) – Member can write content to file or Create, list, rename, delete file in a directory
  • Execute (x) –< Member can execute any file like sheel script or enter to the directory, and access files and directories

Changing File Permissions in Linux

The chmod command allows users two ways to set permission on any file. Read below about both options:

Using Symbolic Notation

Just for the reminder, the following symbols are used for file permissions. Here roles are User(u), Group(g), Others(o) and the permissions are Read(r), Write(w), Execute(x).

Roles:

  • u – User
  • g – Group
  • o – Other

Permissions:

  • r – read permission
  • w – write permission
  • x – execute permission

You can combine any symbols to set permission together like User+Group (ug), User+Group+Other (ugo), User+Other(uo).

Similarly, you can do the same with permissions like Read+Write (rw), Read+Execute (rx), Read+Write+Execute (rwx).

User => Read + Execute

chmod u+rx filename

User + Group => Read + Execute

chmod u+rx,g+rx filename

chmod ug+rx filename

User => All, Group => Read + Execute, Other => Read

chmod u+rwx,g+rx,o+r filename

User => All, Group + Others => Read + Execute

chmod u+rwx,go+rx filename

All permission to everyone (not recommended)

chmod ugo+rwx filename

Using Octal Notation:

Using the octal notation you can set permissions in number between 0-7. Each number is calculated with the sum of read (4), write (2) and execute (1).

For example, if you set permission 6, it means 4+2 (read + write). If you set permission 5 means 4+1 (read + execute).

The permissions are set in a sequence user, group, others. For example if you set permission 754, it means user => 7, group => 5 and other => 4.

Let’s have some examples.

  • Read (r) – 4
  • Write (w) – 2
  • Execute (x) – 1

Possible combinations as as follows:

7 - 4+2+1  (rwx)  (Read + Write + Execute)
6 - 4+2    (rw-)  (Read + Write)
5 - 4+1    (r-x)  (Read + Execute)
4 - 4      (r--)  (Read)
3 - 2+1    (-wx)  (Write + Execute)
2 - 2      (-w-)  (Write)
1 - 1      (--x)  (Execute)
0 - 0      (---)  (None)

Example:

User => read+write+execute, Group => read+execute, Other => read

chmod 754 filename

Here:

  • 7 is for user is combined with read-4 + write-2 + execute-1
  • 5 is for group is combined with read-4 + execute-1
  • 4 is for other is read-1 only.

User => read+write, Group => read+write, Other => read

chmod 664 filename

Share it!

Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy