[ Pobierz całość w formacie PDF ]
.If you create the file, you can changeany of these permissions.The next group of three characters is for the group.If you22recall the discussion of the /etc/passwd file in Hour 21, Basic System Administration,you know that by default, you are assigned to two groups when your account is first cre-ated, one with your name and the other to the group users.As the system administrator,or sysadmin, you can organize users on your system by assigning users to differentgroups.You ll find a list of groups for your Linux system in the group file in the /etc directory.This file contains a text database of groups.Here are a few sample entries:root::0:wheel::10:bin::1:bin,daemondaemon::2:bin,daemonsys::3:bin,admadm::4:adm,daemon.users::100:bball,cloobiebball::500:bballcloobie::502:cloobieThe format of the /etc/group file is group, password, group number, and a comma-delimited list of users who belong to the group.This means that you can assign read,write, or execute permissions to your group and allow or deny access to your files.As theroot operator, or sysadmin, you can organize your users into different groups.This isimportant and is one of the reasons you might need to use the chown (change ownership)command, as you ll see later in this hour.The final set of three characters denotes the read, write, and execution permissions yougrant all other users.Now that you know how to read the permissions, take a look atsome examples before moving on to the chmod program.When you create a file, by default, you and the members of your group have read andwrite permissions on that file.You can change the default of file creation permissionswith your shell s umask command.(See your shell s manual page for details.) Here s asimple example:# touch myfile# ls -l myfile-rw-r--r-- 1 bball users 0 Dec 26 09:29 myfile28 526-2 Ch22 8/26/99 10:59 AM Page 494494 Hour 22This shows that only you (rw-) can read and write the file myfile, whereas your group(r--) and all others (r--) can only read the file.If myfile were available to everyone onyour system, the permissions would look like this:-rw-rw-rw- 1 bball users 0 Dec 26 09:29 myfileNow, anyone (rw-) can read or write this file.If myfile were only available for readingand writing to you, the permissions would look like this:-rw------- 1 bball users 0 Dec 26 09:29 myfileThis shows that you (rw-), but not your group (---) or others (---), can read the file.How do you change these settings? You use the chmod command.Changing File Permissions with the chmodCommandYou can use the chmod command in several ways to change file or directory permissions.Learning how to use this command is not as easy as 1-2-3, but it is as easy as 4-2-1!You can use the chmod command in at least two different ways.Although you can usechmod to create simple commands from text files, using the +x command-line option (asyou learned in Hour 6, Using the Shell ), you might want to set exact permissions ofcertain files in your home directory, or as the sysadmin, of critical files on your system.The chmod command uses octal, or base eight, notation in modifying file or directorypermissions.The 4-2-1 sequence corresponds to the three rwx sequences in the permis-sions flags.How does this work? Well, suppose you want to make one of your files private so that noone else (except the root operator, of course) can read or write your file.When you firstcreate the file, perhaps you and your group can read and write the file, whereas otherscan only read it.Knowing that 4-2-1 matches rwx, and knowing that the group and otherspermissions follow your permissions in the permissions flag, you can use chmod with theoctal number 600 to change the permissions:# chmod 600 afile# ls -l afile-rw------- 1 bball users 0 Dec 26 14:50 afile28 526-2 Ch22 8/26/99 10:59 AM Page 495Handling Files and Your File System 495This makes the file readable and writable only by you because you ve enabled read (4) +write (2) for yourself and no one else.To change the file permissions back to the original22access permissions, you would want to enable read (4) + write (2) for you (6) and yourgroup (6) and read-only permissions for all others (4), and use the octal number 664:# chmod 664 afile# ls -l afile-rw-rw-r-- 1 bball users 0 Dec 26 14:50 afileYou can also change file directory permissions and either let other people list the con-tents of your directory or have access only to the files in a directory and not be able tolist the directory contents.For example, to protect a directory from prying eyes (again,from everyone but the root operator), you can try# mkdir temp# cd temp# touch file1 file2 file3# cd
[ Pobierz całość w formacie PDF ]