Section 3.30. Changing a File s Permissions: chmod


[Page 74 (continued)]

3.30. Changing a File's Permissions: chmod

Now that the file's group was changed, it was necessary to update its permissions, or mode, to deny all access rights to general users. To do this, I used the chmod utility (Figure 3-40).

Figure 3-40. Description of the chmod command.

Utility: chmod -R change { , change }*{ fileName }+

The chmod utility changes the modes of the specified files according to the change parameters, which may take the following forms:

clusterSelection+newPermissions (add permissions)

clusterSelection-newPermissions (subtract permissions)

and

clusterSelection=newPermissions (assign permissions absolutely)

where clusterSelection is any combination of:

  • u (user/owner)

  • g (group)

  • o (others)

  • a (all)

and newPermissions is any combination of

  • r (read)

  • w (write)

  • x (execute)

  • s (set user ID/set group ID)

The -R option recursively changes the modes of the files in directories. Please see the following text for examples. Changing a directory's permission settings doesn't change the settings of the files that it contains.


To remove read permission from others, I used chmod as follows:

$ ls -l heart.final           ...before. -rw-r--r-- 1 glass      music 213 Jan 31 00:12    heart.final $ chmod o-r heart.final       ...remove read for others. 
[Page 75]
$ ls -l heart.final ...after. -rw-r----- 1 glass music 213 Jan 31 00:12 heart.final $ _


Figure 3-41 gives some other examples of chmod.

Figure 3-41. File permission specifications for the chmod command.

Requirement

Change parameters

Add group write permission.

g+w

Remove user read and write permission.

u-rw

Add execute permission for user, group, and others.

a+x

Give the group just read permission.

g=r

Add write permission for user, and remove read from group.

u+w, g-r


I recommend that you protect your login directory from unauthorized access by not granting write permission for anyone but yourself, and by restricting read and execute permission to yourself and members of your group. Here's an example of how to do this:

$ cd                     ...change to home directory. $ ls -lGd .              ...list attributes of home dir. drwxr-xr-x 45 glass        4096 Apr 29 14:35  . $ chmod o-rx             ...update permissions. $ ls -lGd                ...confirm. drwxr-x--- 45 glass        4096 Apr 29 14:35  . $ _ 


Note that I used the -d option of ls to ensure that the attributes of my home directory were displayed, rather than the attributes of its files.

The chmod utility allows you to specify the new permission setting of a file as an octal number. Each octal digit represents a permission triplet. For example, if you wanted a file to have the following permission settings:

rwxr-x-- 


then the octal permission setting would be 750, calculated in Figure 3-42.

Figure 3-42. Permission of 750 for the chmod command.
 

User

Group

Others

setting

rwx

r-x

---

binary

111

101

000

octal

7

5

0



[Page 76]

The octal permission setting would be supplied to chmod as follows:

$ chmod 750 .      ...update permissions. $ ls -ldG          ...confirm. drwxr-x--- 45 glass     4096 Apr 29 14:35  . $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net