Permissions

Understanding permissions

ls -la: Lists all files/folders in a directory, including hidden files/folders.

Example1: .bashrc is a file(Indicated by -), and the owner can read and write to it, but not execute. The group it belongs to can read it, but not write or execute, and any other user can't do anything with the file.

Example2: .config is a directory(Indicated by the d), and the owner is able to read, write, AND execute, the group can read and execute, but not write, the sme goes for any other user as well.

For the .bashrc file:

Modifying Permissions

A new file named hello.txt By default we can only read and write, the group can do the same, other users can only read it.

To change the permission, you run chmod which stand for change mode. Eg. chmod 777 will give full read, write, execute permissions to everything and everyone. Eg. chmod +x will make the file executable to everyone.

To use chmod to set permissions, we need to tell it:

  • Who: Who we are setting permissions for.

  • What: What change are we making? Are we adding or removing the permission?

  • Which: Which of the permissions are we setting?

The β€œwho” values we can use are:

  • u: User, meaning the owner of the file.

  • g: Group, meaning members of the group the file belongs to.

  • o: Others, meaning people not governed by the u and g permissions.

  • a: All, meaning all of the above.

If none of these are used, chmod behaves as if β€œa” had been used.

The β€œwhat” values we can use are:

  • –: Minus sign. Removes the permission.

  • +: Plus sign. Grants the permission. The permission is added to the existing permissions. If you want to have this permission and only this permission set, use the = option, described below.

  • =: Equals sign. Set a permission and remove others.

The β€œwhich ” values we can use are:

  • r: The read permission.

  • w: The write permission.

  • x: The execute permission.

Eg. Changing the permission to remove read permissions to a file: chmod o-r filename.

Eg. Changing the file to be able to be executed: chmod +x script.sh

Last updated