Databases Reference
In-Depth Information
When the operating system is asked to allow access to a file or directory, it looks to see
who the user is and what groups this user belongs to. It then checks the user and the
group associated with that file or directory, and allows access only if the permission
settings are appropriate.
Your group on a Linux or Mac OS X system is typically the same as your username, so,
for example, the username and group for the user adam would both be adam . The user
and group associated with a file or directory can be changed by using the chown com-
mand and specifying the username and group as username : group . For example, you can
set the owner of myfile.txt to be adam , and the associated group to be managers , by typing:
# chown adam:managers myfile.txt
Only the superuser is allowed to change the owner of a file or directory.
You can allocate permissions to a file or directory by using the chmod command. To
allow the user who owns the file myfile.txt to read and write (modify) it but allow other
users to only read it, you would write:
$ chmod u=rw,g=r,o=r myfile.txt
You can also ensure that only the user who owns the file can read and write to the file
as follows:
$ chmod u=rw,g=,o= myfile.txt
Here, the group and other users have been assigned no permissions. Similarly, you can
give everyone read, write, and execute permissions to the directory mydir by typing the
command:
$ chmod u=rwx,g=rwx,o=rwx mydir
When reading other documentation, you'll probably also come across cases where an
octal value (or mask ) is used with the chmod command. In this notation, read access has
the value 4, write access has the value 2, and execute access has the value 1. So, read-
only access has the value 4, but read-and-write access has the value 4+2=6. Our pre-
vious two examples would be written as:
$ chmod 644 myfile.txt
and:
$ chmod 777 mydir
The chown or chmod operation can be applied to all files and directories under a specified
directory by using the --recursive option (under Linux) or the -R option (under Mac
OS X as well as Linux). We'll see examples of this later in this chapter.
 
Search WWH ::




Custom Search