Understanding Linux File Permissions


This post will explain the concept of file permissions so we can get more understanding and after that I will give an instruction to modify it. Operating systems have more than one type of accounts where every single of account can be a member from one or more groups. I will describe this by a simple example. Bob is a single person that in this case Bob is an accounts, but Bob also a members of graduate student from local University and he work as a journalist. This two society members called as a groups in terms of operating systems. There are very lot of groups in Linux that can be build and assign depends on the system services. By this post, I will take only two of Linux default groups that will often needs to modify which are root and users groups.

terminal

The third and fourth column above told us about accounts owner and groups. As we can see file notepad is belong to muhrizky from users group.

Below is the command line syntax to take file ownership:
chown owner[.group] file

In case to change the file notepad ownership into root for example, you can execute:
#chown root.root notepad.txt

I will continue about permissions in more details. The first column from the image above is the specific file and directory permissions applied, where the first character show the type of object which are:

– for files
d for directories
l for file/directory symbolic links
c for character objects
b for block of objects
n for network objects

The next three sets of character defines an access permissions:

r for read
w for write
x for execute

So the file notepad have it’s permissions to read and write for the owner, read-only for users group members, and also for everyone else.

This is the command line format to change file or directory permissions:
chmod mode file

Where specific format for mode are:
[ugoa][+-=][rwx]

The first character bracket for mode defines as:

u for users
g for group
o for everyone else
a for All

The second bracket is a symbolic characters that can be modify to your needs whether to add (+), remove (-), or assign (=) permission.

Finally, the third bracket is to set access for read (r), write (w), or execute (x).

For example to modify notepad so it can be write by everyone, we can type:
$chmod a+w notepad

Besides doing that procedure, you can also modify file or directory by referring that to an octal codes for permissions. The codes are:

0 for no permissions
1 for execute-only
2 for write-only
3 for write and execute
4 for read-only
5 for read & execute
6 for read & write
7 for read, write & execute

In order to change the file permission into full-access for the owner, read-only for group, and also read-only access to everyone, you can type:
$chmod 744 notepad

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: