Linux

Changing Permissions: chmod

The chmod command-line utility allows you to change the permission settings of a file. The format of the command is as follows:

[root@local host ~]#chmod <permissions> <dir/file>
Now back to the permissions.
By default permission 755 is set on the folder we can change the permission by using chmod command. Root make a directory "sony".
chmod
chmod

Its default permission is 755, i want to change it. This can be done by chmod command.
Linux chmod
chmod

See the effect. Permission changes ! All (user, group member, others) have right to do any thing in sony directory.
Linux chmod
chmod

Now play with options.
Now we want to change the all permissions of all files in /home/mohit/max. The -R for all files -v for verbose mode to see the effect.
Linux chmod -R -v
chmod -R -v

Another way to write.
Linux chmod -R -v
chmod -Rv

Ok see the effect.
Linux chmod -R -v
chmod -Rv

All user have permission to do anything in /home/mohit/max directory. At this stage you would have well acquainted with users group and permission now Question is how to use? where to use ?
Ok consider other example. The root user make a directory /exp then root set "thehard" as group owner of /exp as shown in figure.
Linux chmod -R -v
chmod

By default permission is 755. Now root changes the permission. Set 770 it means owner and group member have full right but others' have no right for /exp.
Linux chmod -R -v
chmod permission

Consequently
Linux chmod -R -v
chmod permission

To verify this, first of all I remember you the member of "thehard" group. Ok open the file /etc/group
Linux chmod -R -v
chmod permission

It means mohit, mmm, mohitraj have rights to do any thing.
Ok Let us verify it. Login as mohitraj access (execute or open the folder) the /exp.
Linux chmod -R -v
chmod permission

Wow !!! it works Now login as other users say clip.
Linux chmod -R -v
chmod permission

Oh !!! permission denied . I think now you can easily under stand the advantages of group and permissions.
Now play with some more examples. In above example this is prove that now /exp directory is safe from other users but what about "thehard" group users. The mohitraj user creates two files "hit" and "mo" in /exp directory as shown in figure.
Linux chmod -R -v
chmod permission

The mmm user also create 1 file "ex" in /exp directory.
Linux chmod -R -v
chmod permission

If mmm user want to delete the file of mohitraj, is it possible ?
Linux chmod -R -v
chmod permission

Oh!!! mmm can delete the file "hit" written by mohitraj.
Ok where is security!!!

sticky bit

Here is the concept of sticky bit we add extra sticky bit in chmod command. How to use ?
Linux sticky bit
sticky bit

In above figure 1 is sticky bit which prevent the group user to delete other user files
Linux sticky bit
sticky bit

T shows that we are using sticky bit.
Verify the result
Now user mmm can't delete the file 'mo' created by mohitraj as shown in figure below.
Linux sticky bit
sticky bit

There is another syntax for chmod that change the permissions, which constitutes the symbolic mode. its general form is,
[root@localhost ~]# chmod <+/-/=> <>permission> file
The Who here refers to whom the permission are to be assigned.
It may be owner ( u)
Group ( g)
Others ( o)
The + refers to add permission, - refers to remove permission and = instructs chmod to add the specified permission and take away all other, if present
The specified permission if course, can be r,w,x, and t.
Here are some examples;
Linux Symbolic Method  permission
Linux Symbolic Method permission

Adding write permission to group and others for file "kl".
Linux Symbolic Method  permission
Linux Symbolic Method permission

Removing read permission to group and others for file "kl".
Linux Symbolic Method  permission
Linux Symbolic Method permission

Linux Symbolic Method  permission
Linux Symbolic Method permission

Making group and others permissions equal to read, whatever the old permissions.
Linux Symbolic Method  permission
Linux Symbolic Method permission

Subtracting all permissions as shown in figure.
Linux Symbolic Method  permission
Linux Symbolic Method permission

Use of =, this equal to symbol equals the permission of left side with the right side.
Linux Symbolic Method  permission
Linux Symbolic Method permission

I hope you have understood the entire chapter.




admin