United States (change)
Shortcuts: Downloads Fedora Red Hat Network
Account Links: Cart Your Account Logout
-rw-rw-r-- 1 sam users 150 Mar 19 08:08 sneakers.txtThe file sneakers.txt belongs to, or is owned by sam.
-rw-rw-r--Those three sets are the owner of the file, the group in which the file belongs, and "others," meaning all other users.
- (rw-) (rw-) (r--) 1 sam users | | | | type owner group othersThe first item, which specifies the file type, typically shows one of the following:
ls -l sneakers.txt -rw-rw-r-- 1 sam users 150 Mar 19 08:08 sneakers.txtThe file's owner (in this case, sam) has permission to read and write to the file. The group, users, has permission to read and write to sneakers.txt, as well. It is not a program, so neither the owner or the group has permission to execute it. All other users can only read the file.
chown sam:sam sneakers.txt ls -l sneakers.txt -rw-rw-r-- 1 sam sam 150 Mar 19 08:08 sneakers.txtresults in the user sam owning the file. The group owner of the file is also set to sam's group which happens to be called sam also.
ls -l sneakers.txtThe previous command displays this file information:
-rw-rw-r-- 1 sam sam 150 Mar 19 08:08 sneakers.txtNow, you would type the following:
chmod o+w sneakers.txtThe above command tells the system you want to give others write permission to the file sneakers.txt. To check the results, list the file's details again. Now, the file looks like this:
-rw-rw-rw- 1 sam sam 150 Mar 19 08:08 sneakers.txtNow, everyone can read and write to the file.
chmod go-rw sneakers.txtBy typing go-rw, you are telling the system to remove read and write permissions for the group and for others from the file sneakers.txt.
-rw------- 1 sam sam 150 Mar 19 08:08 sneakers.txtThink of these settings as a kind of shorthand when you want to change permissions with chmod, because all you really have to do is remember a few symbols and letters with the chmod command.
u - the user who owns the file (that is, the owner) g - the group to which the user belongs o - others (not the owner or the owner's group) a - everyone or all (u, g, and o)Permissions:
r - read access w — write access x — execute accessActions:
+ — adds the permission - — removes the permission = — makes it the only permissionWant to test your permissions skills? Remove all permissions from sneakers.txt — for everyone.
chmod a-rwx sneakers.txtNow, see if you can read the file with the command cat sneakers.txt, which should return the following:
cat: sneakers.txt: Permission deniedRemoving all permissions, including your own, successfully locked the file. But since the file belongs to you, you can always change its permissions back with the following command:
chmod u+rw sneakers.txtHere are some common examples of settings that can be used with chmod:
g+w - adds write access for the group o-rwx - removes all permissions for others u+x - allows the file owner to execute the file a+rw - allows everyone to read and write to the file ug+r - allows the owner and group to read the file g=rx - allows only the group to read and execute (not write)By adding the -R option, you can change permissions for entire directory trees.
mkdir tiggerThen type:
chmod a-x tiggerto remove everyone's execute permissions on the directory tiger.
bash: tigger: Permission deniedNext, restore your own and your group's access:
chmod ug+x tiggerNow, if you check your work with ls -l you will see that only others will be denied access to the tigger directory.
-rw-rw-r-- 1 sam sam 150 Mar 19 08:08 sneakers.txtEach permission setting can be represented by a numerical value:
r = 4 w = 2 x = 1 - = 0When these values are added together, the total is used to set specific permissions. For example, if you want read and write permissions, you would have a value of 6; 4 (read) + 2 (write) = 6.
- (rw-) (rw-) (r--)
| | |
4+2+0 4+2+0 4+0+0
The total for the user is six, the total for the group is six, and the total for others is four. The permissions setting is read as 664.
chmod 644 sneakers.txtNow verify the changes by listing the file.
ls -l sneakers.txt -rw-r--r-- 1 sam sam 150 Mar 19 08:08 sneakers.txtNow, neither the group nor others have write permission to sneakers.txt. To return the group's write access for the file, add the value of w (2) to the second set of permissions.
chmod 664 sneakers.txtWARNING:
-rw------- (600) - Only the owner has read and write permissions.
-rw-r--r-- (644) - Only the owner has read and write permissions;
Tthe group and others have read only.
-rwx------ (700) - Only the owner has read, write, and execute permissions.
-rwxr-xr-x (755) - The owner has read, write, and execute permissions;
The group and others have only read and execute.
-rwx--x--x (711) - The owner has read, write, and execute permissions;
The group and others have only execute.
-rw-rw-rw- (666) - Everyone can read and write to the file.
(Be careful with these permissions.)
-rwxrwxrwx (777) - Everyone can read, write, and execute.
(Again, this permissions setting can be hazardous.)
Here are some common settings for directories:
drwx------ (700) - Only the user can read, write in this directory.
drwxr-xr-x (755) - Everyone can read the directory;
users and groups have read and execute permissions.