Understanding Linux file permissions
directory, this attribute decides whether you have permission to enter,
run a search through that directory or execute some program from that
directory.
Take the permissions of tmp, which are drwxr-x---. The owner of this
directory is user mayank and the group owner of the directory is freeos.
The first 3 permission attributes are rwx. This permission allows full
read, write and execute access to the directory to user mayank. So, mayank
has full access here. The group permissions are r-x. There is no write
permission given here so while members of the group freeos can change into
the directory and list its contents, they cannot create new files or
sub-directories. They also cannot delete any files or make changes to the
directory content in any way. No one else has any access because the
access attributes for others are empty (---).
For foo the permissions are -rw-r--r--. Apply the above and you will see
that the owner of the file (mayank) can read and modify the file (Read and
Write access). Members of the group freeos can read the file but cannot
modify it. Everyone else can also read the file but not make any changes
to it.
Now that you can read file permissions, you should learn about how you can
set or modify permissions. You would use the chmod program for this. To
change file permissions, you need to be either the user or root. The
syntax of the chmod command is quite simple. File permissions may be
defined for users (u), groups (g) and others (o).
An example of the chmod command will be
chmod u-x,g+w,o+rw somefile
The chmod command here takes away execute permission from the user, sets
the write access bit for the group and also gives read and write access to
everyone else. The file permissions for the file before this command is
executed are -rwxr-xr-. After this command, the file permissions are
-rwxrwx---. First you choose to use 'u','g' or 'o' followed by '+' to add
a permission, '-' to take it away and '=' to wipe out any previous
permission bits and set the permission bits to what is specified. You can
also use 'a' to set a permission bit for all users.
Let's take permissions of -rwxrwxrwx for somefile and work on them.
chmod g-wx somefile
We're removing write and execute permission for members of the group. The
file will now have attributes of -rwxr-rwx.
You can also specify permissions for users, groups or others in the same
command, separated but commas.
- « first
- ‹ previous
- of 4
- next ›
- last »