Thursday, July 3, 2008

Understanding File Permissions in Linux Systems

Understanding File Permissions in Linux Systems
Every file or directory in the Linux file system contains settings for who can read, write or execute the file. These settings are called permissions. Each file or directory is assigned to a specific user and group.

Permissions

Each file or directory has three security groups,
• Owner (Each file or directory has a specific owner or creator)
• Group Access (Each file or directory is assigned to a specific group)
• All Others (If a user is not the owner or is not assigned to the group, those are considered as others)
Each security group has 3 flags that control the access status
Flag 1 = read Flag 2= write Flag 3 = execute
They are listed as 'rwx' or a "-" if the access is turned off.
To view the permissions, you use the ls -l or ll command.
For each file or directory listed, you will see the permissions, owner and group name, and file or directory name.

Examples
-rwxrwxrwx read, write and executable for owner, group and all others
-rwxrwx--- read, write and executable for owner, group only
-rwx------ read, write and executable for owner only
-rw-rw-rw read and write for owner, group and all others
-rwxr-xr-x read, write and executable by owner, only read and executable by group and others
-rw-r--r- read and write by owner, read only for group and all others

Changing Permissions - chmod -
Use “chmod” to change the permissions.

Options:
u, g, o or all Whose permission you are changing: user, group, other or all
+ or - Type of change: add permission or subtract permission combination of
r , w or x which permission you are changing: read, write or execute
file or directory name of file or directory to change

Examples
chmod go-w testFile remove write access for group and others for the file ‘testFile’
chmod go+rw file1 file2 add read and write access for group and others for files 'file1' and 'file2'
chmod ugo+rwx testFile1 add read, write and execute for everyone for 'testFile1'.

Changing Owner - chown -
Use “chown” to change the owner of a file or directory.
Command: chown username
Example: To change the owner of 'file1' and 'file2' to the user 'chinmay'
chown chinmay file1 file2

Changing Group - chgrp -
Use “chgrp” to change the group of a file or directory.
Command: chgrp groupname
Example: To change the group of 'testFile1' and 'testFile2' to the group 'development'
chgrp development testFile1 testFile2

No comments: