Linux chmod commands example and implementations
In our last two articles you learnt about permission. Permission can be set by chmod command in two different way symbolic and binary masks.
In this article we will practically implements whatever you have learnt so far in file permissions. This article is a sequential of last two articles if you have missed last two articles we suggest you to review them before going through this first.
Create 3 user a b c without password. Use for loop despite of creating them separately. You have learnt about this in our advance user managements assignments.
#for user in a b c >do >useradd $USER >passwd –d $USER >done
Now create a group example and add user a and b to in.
#groupadd example #usermod –G example a #usermod –G example b
now create a test director y on root partition and change ownership to user a and group to example.
Now logon 3 separate terminals form these users.
From root set permission to
#chmod 700 /test
This will set permissions to
owner a full group example ( a ,b ) none other c none
to verify these permission go on the terminals where user a is logged on and
$cd /test $cat > a_file This is a file of user a $ls a_file
user a will able to do all three task read write execute as owner have all three permission Now try to change /test directory form user b . It will deny. Because user b remain in example group. and group have no permissions.
Now try to change /test directory form user c. it will also deny. Because user c is other for this directory and other have no permissions.
Now change permission from root to
#chmod 710 /test
This will give full permission to owner a. And execute to b ( b is in the group of a which is example) User c (other ) still have no permissions.
To verify try change directoy form user b to /test is should success but he will not able to list the contain of directory.
$cd /test $ls
Also verify the permission of c ( other ) by changing the directory to /test
$cd /test
Now change permission from root to
#chmod 751 /test
This will give full permission to owner a. execute and read to b ( b is in the group of a which is example) User c (other ) now have execute permissions.
To verify try to list form user b to /test is should success but he will not able to write in directory.
$ls $cat > b_file
Also verify the permission of c ( other ) by changing the directory to /test
$cd /test $ls
Now change permission from root to
#chmod 775 /test
This will give full permission to owner a b ( b is in the group of a which is example) User c (other ) now have read and execute permissions.
To verify try make new file form user b to /test is should success.
$cd /test $ls $ cat > b_file This file is created by b
Also verify the permission of c ( other ) by listing the directory to /test
$cd /test $ls
Now change permission from root to
#chmod 777 /test
This will give full permission to owner a b and c. User c (other ) now have full permissions.
To verify make file form user c
$ cat > c_file This file is created by user c
No comments:
Post a Comment