Website based on my experience working as System Administrator

LINUX INFORMATION WEBSITE

This site is dedicated to providing tutorials, help, guides and links for Linux users.
HOME PAGE
LINUX COMMANDS
   
   
   
   
   
   
   
   
   

LINUX COMMANDS

Contents | Previous | Next

Access rights

Every user belongs to atleast one group, their login group - given the same name as their user account.

Every file belongs to an owner and group. Usually the user that created the file and that user's login group. To display the owner and group a file belongs to, enter:

ls -l

...and examine the third (owner) and fourth (group) columns:

-rw-rw-r--   1 john john   10760 Nov 20 16:50 report.txt


$ groups

groups
Display groups you belong to.


groups john
Display groups john belongs to.


# chgrp - change group

chgrp john report.txt
Change group of file report.txt, to john.


chgrp -R john .
Change group of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.


# chown - change owner

chown john report.txt
Change owner of file report.txt, to john.


chown -R john .
Change owner of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.


chown -R john:john .
Change owner and group (owner:group) of all files and subdirectories (i.e. -R for recursively) in the current (.) directory, to john.


$ chmod - change mode

Entering ls -l will display in the first column, the permissions for each file and directory, in the current directory.

For example:

-rw-rw-r--   1 john john   10760 Nov 20 16:50 report.txt

Here's how it breaks down:

Type Owner Group Other
- rw- rw- r--


Type

Character Description
- Normal file.
d Directory.
l Symbolic link.


Owner, group, and other

The owner, group, and other sections, each have three entries: r (read); w (write); x (execute)

An r, w, or x, means that permission is given, a hypen (-) means it isn't. For example:

-rw-rw-r--

...indicates a normal file, with read/write but no execute permissions given to the owner and group, and all other users just have read permission.


Setting permissions: method one

Example Description
chmod +r report.txt Give read permission to all.
chmod -r report.txt Remove read permission from all.
chmod =r report.txt Give nothing but read permission to all.
chmod +w report.txt Give write permission to owner and group.
chmod -w report.txt Remove write permission from owner and group.
chmod =w report.txt Give nothing but write permission to owner and group.
chmod +x report.txt Give execute permission to all.
chmod -x report.txt Remove execute permission from all.
chmod =x report.txt Give nothing but execute permission to all.

In front of any of the above you can add:

Example Short for
u user
g group
o other
a all (same as: ugo)


Examples

chmod a+rw report.txt
Give all users read and write permission (what's called making the file report.txt, world readable and world writable).


chmod go-w report.txt
Remove write permission (-w) from report.txt for group and others (go), allowing only the owner modify the file (as long as they had write permission beforehand).


chmod go= report.txt
Remove all permissions for group and others (go), making the file report.txt private to owner.


Setting permissions: method two

Permissions can also be set in octal (base 8), where read permission is a four, write is two, and execute is one. These you add up separately for user, group and other for between 000 (---------) and 777 (rwxrwxrwx), like so:

 

Contents | Previous | Next

 
Last Update: Jan 2003

HOME | CONTACT | FAQ'S | TRICKS & TIPS | WEIRD NEWS
This Material has been taken from different sources. Its free for anyone to use and reproduce.