Manage File Permissions and Ownership

«« Previous
Next »»

Weight 2
Description  Understanding and manipulating file permissions and ownership settings.

Key Knowledge Areas:

◉ File/directory permissions and owners.

The following is a partial list of the used files, terms and utilities:

◉ ls -l.
◉ chmod, chown.

Nice to know:

◉ chgrp.

For this objective we take a look at the permissions or “mode” of a file, (or directory).  The permissions can be set for the:

◉ user owner
◉ group owner
◉ and others

The available permissions are simply read, write and execute. Execute permissions to a directory mean that you can enter the directory, or more specifically traverse the directory link, the word enter works perfectly well for me.

The permissions for a file are normally read from the long listing of ls (/bin/ls):

ls -l

for a file or, for a directory:

ls -ld

The permissions shown from ls are displayed in symbolic form, ie rwx. Permissions can in set in symbolic format or octal format such as 755. If you would like to display the permissions in octal format, the command stat (/usr/bin/stat) could be used:

stat -c %a /etc (octal)

stat -c %A  /etc (symbolic)

Manage File Permissions and Ownership

Output from stat

From the output above we can see the 755 permissions relate to rwxr-xr-x.

We can use chmod (/bin/chmod) to set the permissions whereas we use ls -l to display permissions, ls -ld is needed to display the permissions for a directory. When using chmod there are two methods of setting permissions, with octal or symbolic notation:

◉ chmod 755 file1
◉ chmod u=rwx,g=rx,o=rx file

Ownership of files can be changed using chown (/bin/chown) to change the user owner and chgrp (/bin/chgrp).


«« Previous
Next »»

0 comments:

Post a Comment