Monday, May 5, 2008

Setting Permissions

Linux works with three entities that can be set as the owner of the file or directory. Those are owner, group owner and others.

ls -l command provide the detailed information of files in a directory. The first column of the output shows 10 permission bits something like -rwxr-xr-x

For example:

# ls -l

-rwxr-xr-x 1 alexander users 1024 2008-05-06 11:20 somefile

(# in above example, is command prompt)

The first bit says the type of the file. Mostly it is - which means it is a regular file. If it is d means, it is a directory and etc.

The next three bits says the permissions (r-read, w-write, x-execute) for owner of the file.

The next three bits says the permissions for the group and last three bits says the permission for others.

The owner of the file or Administrator can change the permission of a file using chmod command.

chmod entity + or - permission(s)

For example, to remove executable permission for others for file somefile

chmod o-x somefile

to add write permission for group for file somefile

chmod g+w somefile

Permissions are

r - read
w - write
x - execute
s - set user or group id
t - sticky bit

If set user or group id is given for a file, the execute (x) permission of respective entity (user or group) will be replaced with s

For example, if set user id is given fo somefile, it looks like below output

-rwsr-xr-x 1 alexander users 1024 2008-05-06 11:20 somefile

If sticky bit is set to a file, t will be added at last bit of permissions

For example, if sticky bit is set to
somefile, it looks like below output

-rwsr-xr-t 1 alexander users 1024 2008-05-06 11:20 somefile



No comments: