chmod command can be use to change different permission configurations. chmod takes two lists as its arguments: permission changes and filenames.
You can specify the list of permissions in two different ways. One way uses permission symbols and is referred to as the symbolic method. The other uses what is known as a “binary mask” and is referred to as either the absolute or the relative method.
Binary Masks
When dealing with a binary mask, you need to specify three digits for all three categories, as well as their permissions. This makes a binary mask less flexible than the permission symbols.
The -S option uses the symbolic format.
You can set a new default by specifying permissions in either symbolic or binary format. To specify the new permissions, use the -S option. The following example denies others read permission, while allowing user and group read access, which results in permissions of rwxr-x---:
The following example shows the mask for the permission defaults rwx, rx, and rx (rw, r, and r for files):
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

In our pervious articles we have discussed about read write and execute permission for file and directory. Now I will show you some special permission which you can set for files and directories.
s permission
is used to deal with this situations. s options is used to add both user ID and group ID permission to a file.
The following example add's user ID permission to the pppd program, which is owned by the root user. When an ordinary user runs pppd, the root user retains ownership, allowing the pppd program to change root-owned files.
# chmod +s /usr/sbin/pppd The Set User ID and Set Group ID permissions show up as an s in the execute position of the owner and group segments. Set User ID and Group ID are essentially variations of the execute permission, x. Read, write, and User ID permission are rws instead of just rwx.
# ls -l /usr/sbin/pppd -rwsr-sr-x 1 root root 18666 Jan 12 12:48 /usr/sbin/pppd
# chmod +t /home/vinita/data # ls -l /home/vinita/data -rwxr-xr-t 1 root root 4096 /home/vinita/data
# chmod 1755 /home/vinita/data The next example sets both the sticky bit and the User ID permission on the newprogs directory.
# chmod 5755 /usr/bin/newprogs # ls -l /usr/bin/newprogs drwsr-xr-t 1 root root 4096 /usr/bin/newprogs
#useradd vinita #passwd –d vinita #useradd nikita #passwd –d nikita #mkdir /example
As example directory is created by root so the owner and group of this directory will root. By default permission will be inherited to all other object created in this directory to root owner. Now we will use symbolic method to change the ownership issue to this directory.
#chmod ugo+rwxs /example #ls –ld /example
As you can see in image s bit is set in owner and group filed which will automatically set owner and group to their respective owner and group. To verify login form user nikita and change directory to example and creates a file.
$cd /example $cat > nikita_file This is the file of nikita $ls –l
As you can see owner filed is changed to user nikita.
Now create a file form user vinita.
$cd /example $cat > vinita_file This is file of Vinita $ls –ld
Now you can understand what s bit do in chmod command. This is best options when users are working on some shared project. As they will gets ownership of their files automatically.
To control this behaviors switch to root user and set sticky bit on /example folder.
#chmod o+t /example #ls –ld /example
Sticky bit is defined by t options. As you can see in output other have t bit set in their filed. Now only owner of file and root user can delete file in this folder.
To verify switch Vinita user again and try to delete the files of nikita. This time it will not success this time.
To remove sticky bit use minus sign.
#chmod o-t /example
now Vinita can delete the files owned by nikita verify

You can specify the list of permissions in two different ways. One way uses permission symbols and is referred to as the symbolic method. The other uses what is known as a “binary mask” and is referred to as either the absolute or the relative method.
Symbolic Method
The symbolic method of setting permissions uses the characters r, w, and x for read, write, and execute, respectively. Any of these permissions can be added or removed. The symbol to add a permission is the plus sign, +. The symbol to remove a permission is the minus sign, -.chmod :- File Permissions in Symbolic Method
| Description | |
| r | Read |
| w | Write |
| x | Execute (also gives permission to change into a directory) |
| X | Execute only if it is a directory or has execute permission for some user |
| s | Set user or group ID on execution |
| t | Sticky bit |
| u | Permissions granted to user who owns the file |
| g | Permissions granted to users in the file's group |
| o | Permissions granted to owner of the group and users in the file's group |
r w x permissions
The first three (r, w, x) are clear. Use them to set read, write, and execute permissions.s permission
The s permission is used on directories to keep the user or group ID for a file created in the directory. To set the user ID for any new files created in the directory to the owner of the directory, use the chmod u+s <directory> command. To set the group ID for any new files created in the directory to the directory's group, use the chmod g+s <directory> command.t permission
t is a special permission which provides greater security on directories. Sticky bit is used for directories to protect files within them. Files in a directory with the sticky bit set can only be deleted or renamed by the root user or the owner of the directory.Sticky Bit Permission Using Symbols
The sticky bit permission symbol is t. The sticky bit shows up as a t in the execute position of the other permissions. A program with read and execute permissions with the sticky bit has its permissions displayed as r-t.#chmod +t /home/vinita/account_detail #ls -l /home/vinita/account_detail -rwxr-xr-t 1 root root 4096 /home/vinita/account_detail
u g o permission
The last three permissions (u, g, o) are only used with the = operator to set permissions for the owner, group, others, or everyone equal to the existing permissions for the owner, group, others, or everyone. For example, chmod g=u [filename] sets the group permissions to the current permissions for the owner of the file.Examples of symbolic method

Absolute Permissions: Binary Masks
The absolute method changes all the permissions at once, instead of specifying one or the other. It uses a binary mask that references all the permissions in each category.Binary Masks
When dealing with a binary mask, you need to specify three digits for all three categories, as well as their permissions. This makes a binary mask less flexible than the permission symbols.
Digits permission 0 none 1 execute 2 write 4 read 3 (1+2) write and execute 5 (1+4) read and execute 7 (1+2+4) read write execute
| Value | Meaning |
| 777 | (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting. |
| 755 | (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users. |
| 700 | (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others. |
| 666 | (rw-rw-rw-) All users may read and write the file. |
| 644 | (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change. |
| 600 | (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private. |
Examples of binary masks
Defaults Permission : umask
Whenever you create a file or directory, it is given default permissions. You can display the current defaults or change them with the umask command. The permissions are displayed in binary or symbolic format. The default permissions include any execute permissions that are applied to a directory. Execute permission for a file is turned off by default when you create it because standard data files do not use the executable permissions (to make a file executable like a script, you have to manually set its execute permission). To display the current default permissions, use the umask command with no arguments.The -S option uses the symbolic format.
#umask -S u=rwx,g=rx,o=rxThis default umask provides rw-r--r-- permission for standard files and adds execute permission for directories, rwxr-xr-x.
You can set a new default by specifying permissions in either symbolic or binary format. To specify the new permissions, use the -S option. The following example denies others read permission, while allowing user and group read access, which results in permissions of rwxr-x---:
#umask -S u=rwx,g=rx,o=When you use the binary format, the mask is the inverse of the permissions you want to set. To set both the read and execute permission on and the write permission off, you use the octal number 2, a binary 010. To set all permissions on, you use an octal 0, a binary 000.
The following example shows the mask for the permission defaults rwx, rx, and rx (rw, r, and r for files):
#umask 0022To set the default to only deny all permissions for others, you use 0027, using the binary mask 0111 for the other permissions.
#umask 0027
Linux chmod commands example and implementations
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
#groupadd example #usermod –G example a #usermod –G example b
From root set permission to
#chmod 700 /test
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
#chmod 710 /test
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
$cd /test
#chmod 751 /test
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
$cd /test $ls
#chmod 775 /test
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
$cd /test $ls
#chmod 777 /test
To verify make file form user c
$ cat > c_file This file is created by user c
chmod commands sticky bit example and implementations
Ownership issue
In some case you want to grant permission to other user while keeping ownership to self.s permission
is used to deal with this situations. s options is used to add both user ID and group ID permission to a file.
The following example add's user ID permission to the pppd program, which is owned by the root user. When an ordinary user runs pppd, the root user retains ownership, allowing the pppd program to change root-owned files.
# chmod +s /usr/sbin/pppd The Set User ID and Set Group ID permissions show up as an s in the execute position of the owner and group segments. Set User ID and Group ID are essentially variations of the execute permission, x. Read, write, and User ID permission are rws instead of just rwx.
# ls -l /usr/sbin/pppd -rwsr-sr-x 1 root root 18666 Jan 12 12:48 /usr/sbin/pppd
Sticky Bit Permissions
Sticky Bit is used for directories to protect files within them. Files in a directory with the sticky bit set can only be deleted or renamed by the root user or the owner of the directory.Sticky Bit Permission Using Symbols
The sticky bit permission symbol is t. The sticky bit shows up as a t in the execute position of the other permissions. A program with read and execute permissions with the sticky bit has its permissions displayed as r-t.# chmod +t /home/vinita/data # ls -l /home/vinita/data -rwxr-xr-t 1 root root 4096 /home/vinita/data
Sticky Bit Permission Using the Binary Method
As with ownership, for sticky bit permissions, you add another octal number to the beginning of the octal digits. The octal digit for the sticky bit is 1 (001). The following example sets the sticky bit for the data directory:# chmod 1755 /home/vinita/data The next example sets both the sticky bit and the User ID permission on the newprogs directory.
# chmod 5755 /usr/bin/newprogs # ls -l /usr/bin/newprogs drwsr-xr-t 1 root root 4096 /usr/bin/newprogs
Sticky bit example of practically implementations
USER ID and GROUP ID Permissions
To understand sticky bit and user permission in more depth let's take an example. Create two user named vinita and nikita. And a example directory on root partitions.#useradd vinita #passwd –d vinita #useradd nikita #passwd –d nikita #mkdir /example
#chmod ugo+rwxs /example #ls –ld /example
$cd /example $cat > nikita_file This is the file of nikita $ls –l
Now create a file form user vinita.
$cd /example $cat > vinita_file This is file of Vinita $ls –ld
Implementation of sticky bit
But this could create other problem. User can accidently or intensely delete other user’s files and folder as all user have full permission on this shared folder. Go on terminal where user Vinita is logged in and delete the file of nikita.#chmod o+t /example #ls –ld /example
To verify switch Vinita user again and try to delete the files of nikita. This time it will not success this time.
#chmod o-t /example
No comments:
Post a Comment