How to change file or folder permission in Ubuntu Linux

Wondering to set permission in Ubuntu Linux using the Terminal?
Here’s how..

The Command

The chmod command sets the permission of a file or folder.
chmod command uses a three digit code as an argument together with the file or folder location.

 sudo chmod 754 /home/nordicvikings/secret_stuff (or your path)

In the example we used the following codes:

  • 7 – Owner(current user)
  • 5 – Group(set by owner)
  • 4 – anyone else

 

The fundamental concept:

Execute is 1, Write is 2 and Read is 4.

Sum of these basic ones makes combination of permissions:

  • 0 – no permission, this person cannot read, write or execute
  • 1 – execute only
  • 2 – write only
  • 3 – execute and write only (1 + 2)
  • 4 – read only
  • 5 – execute and read only (1 + 4)
  • 6 – write and read only (2 + 4)
  • 7 – execute, write and read (1 + 2 + 4)

But what about sub folders?

All Sub folders can easily be changed using the “-R” command.

Here’s an example:

sudo chmod -R 754 /home/nordicvikings/secret_stuff (or your path)

 

Leave a Reply