Share this Page URL

Chapter 4. Unix Security & Utilities > Changing Permissions for a File or Direc... - Pg. 91

Unix Security & Utilities 91 Changing Permissions for a File or Directory Unix includes a command for setting file or directory permissions: chmod. Although this command can be a bit complicated, it is important. The security of your files and subdirectories depend on its proper usage. The chmod command uses the following syntax: chmod mode file ... The complex part of the chmod command is understanding what can go in the mode operand. This is where you specify the owner (also called user), group, and other (everyone else) permissions. You have two ways to do this: numerically and symbolically. Tip · You can learn more about the chmod command by viewing its man pages. In the Ter- minal window, type man chmod and press . Numeric permission modes Numeric permission modes uses numbers to represent permissions options. The best way to explain this is to provide an example. Remember, the nine characters of the per- missions coding in a directory listing can be broken down into three sets of three: rwx user rwx group rwx other Each character can be represented with an octal digit (a number between 0 and 7) by assigning values to the r, w, and x characters, like this: 421 rwx user 421 rwx group 421 rwx other So, if you want to give read and write permission for a file called file1 to the owner, that would be a 4 (read) plus a 2 (write), which adds up to a 6. You could then give read only permission to the group and others by assigning the value 4 (read). The command to do all this is chmod 644 file1. (The 644 permission is one you'll see often on text files that are readable by everyone. A permission of 600 would make a file private.) Symbolic permission modes Symbolic permission modes enables you to add or remove privileges using symbols. For example, to remove write permission from the group and others, type chmod go-w file1. This translates to "take away write permissions from the group and others." The ownership symbols you use for this are: u g o a user (owner) of the file or directory group owner of the file or directory others (everyone) all three (user, group, and others) The symbols for the permissions you can add or take away are: