chmod
Linux Commands - Managing Rights

chmod

This command will change the permissions that are associated with a file or directory. x = execute r = read w = write These are basic rights to files for User(usually creator of the file), Group and Others. u = user g = group o = others all = user, group, others chmod u+x /home/fred/text This command would give all users on the system the execute right for the file /home/fred/text. FILE PERMISSIONS Octal Value Special User Group Others 4 set-UID r r r 2 set-GID w w w 1 sticky-bit x x x Octal system uses 8 values 0-7 as opposed to the decimal which uses 10. Examples: Let's say you have a file named text. If you created the file text, you are the User and would have all rights to the file read/write/execute. If you look above, you see that r,w,x under User will mean all rights. Then if you add the numbers in the left hand column, 4,2,1 you get 7. chmod 700 text This command would mean all rights for User (rwx,421=7), no rights for group (0) and no rights for others (0), that's where the 700 comes from. chmod 755 text This command gives all rights to the User (rwx,421=7), read and execute rights to Group and Others (rx, 4 +1 =5). set-UID when this value is used (ex: 4755) it gives the file the same rights as root when it is run set-GID when this value is used (ex: 2755) it gives the file the same rights as the group of the file sticky-bit this tells the OS to keep an executable program's image in memory to reduce the start time of a large program (used infrequently, ex: 1755) chmod Exercise Create a directory called /home/username/info mkdir /home/ username/info Now that you have a directory called /home/info, let's check the permissions on that directory. ls lF /home You will see something like below drwxr-xr-x 2 root root 4096 Oct 23 05:57 info/ Permissions Links Owner Group Size Last Modified Time File drwxr-xr-x 2 root root 4096 Oct 23 05:57 info/ The owner root has read/write/execute privileges (group = rx, other=rx) Let's change the rights so that group and other can only read. Now use gedit to create a file test and save it in /home/ username/info chmod 0744 /home/ username/info/test Now when you check permissions (ls lF /home/ username/info/test) you will see the following drwxr.r chmod 0724 /home/ username/info/test Now what do you get?