|
table of contents
chmod [-fr] absolute_mode file ... chmod [-fr] [who]+permission ... file ... chmod [-fr] [who]-permission ... file ... chmod [-fr] [who]=[permission ...] file ... the chmod command modifies the read, write, and execute permissions of specified files and the search permissions of specified directories. you can use either symbolic or absolute mode to specify the desired permission settings. you can change the permission code of a file or directory only if you own it or if you have superuser authority. if a named file is a symbolic link, chmod changes the mode of the link's target file unless the -r flag is used. if the -r flag is used, chmod leaves links and their target files untouched. symbolic mode a symbolic mode has the form: [who] operation permission [operation permission] ... the who argument specifies whether you are defining permissions for a user, group, or all others, or any combination of these. the operation argument specifies whether the permission is being added, taken away, or assigned absolutely. the permission argument identifies the operation that the specified users can perform on file. valid options for the who argument are as follows: u user (owner) g group o all others a user, group, and all others (same effect as the combination ugo) if the who argument is omitted, the default is a, but the setting of the file creation mask, umask (see csh, ksh, sh), is applied. valid options for the operation argument are as follows: - removes specified permissions. + adds specified permissions. = clears the selected permission field and sets it to the code specified. if you do not specify a permission code following =, chmod removes all permissions from the selected field. valid options for the permission argument are as follows: r read permission. w write permission. x execute permission for files, search permission for directories. x execute permission only if file is a directory or at least one execute bit is set. s set-user-id or set-group-id permission. this permission bit sets the effective user id or group id to that of the owner or group owner of file whenever the file is run. use this permission setting in combination with the u or g option to allow temporary or restricted access to files not normally accessible to other users. an s appears in the user or group execute position of a long listing (see ls) to show that the file runs with set-user-id or setgroup-id permission. t save text permission. in earlier versions of the unix system, setting this permission bit caused the text segment of a program to remain in virtual memory after its first use. the system thus avoided having to transfer the program code of frequently accessed programs into the paging area. a t appears in the execute position of the all others option to indicate that the file has this bit (the sticky bit) set. if a directory has this bit set, then deletion in it is restricted. an entry in a sticky directory can only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the superuser. the u, g, and o options indicate that permission is to be taken from the current mode. omitting permission is only useful with = to take away all permissions. all permission bits not explicitly specified are cleared. you can specify multiple symbolic modes, separated with commas. do not separate items in this list with spaces. operations are performed in the order they appear from left to right. absolute mode absolute mode lets you use octal notation to set each bit in the permission code. the chmod command sets the permissions to the permission_code you provide. the permission_code is constructed by combining (the logical or of) the following values:
4000
2000
1000 retains memory image after execution (executable file) restricts file removal (directory file) you must be root to set the sticky bit. see chmod(2).
0400
0200
0100
0040
0020
0010
0004
0002
0001 system v compatibility the root of the directory tree that contains the commands modified for svid2 compliance is specified in the file /etc/svid2_path. you can use /etc/svid2_profile as the basis for, or to include in, your .profile. the file /etc/svid2_profile reads /etc/svid2_path and sets the first entries in the path environment variable so that the modified svid2 commands are found first. the svid2 compliant version of the chmod command ignores the umask value if who is not specified in the symbolic mode of the command (chmod [who] operation permission). in other words, if you omit who from the chmod command line, the version of the command that is compliant with the svid2 standard behaves exactly as if you specified the character a as the value for who. the version of the chmod command that is svid2 compliant also supports equivalents in absolute mode for the s permission in symbolic mode. in absolute mode, setting the bits 04000 represents set-user-id and setting the bits 02000 represents set-group-id. -f does not report an error if chmod fails to change the mode on a file. -r causes chmod to recursively descend its directory arguments, setting the mode for each file as described in the sections symbolic mode and absolute mode. when symbolic links are encountered, their mode is not changed and they are not traversed. 1. to add a type of permission to several files, enter: chmod g+w chap1 chap2 this adds write permission for group members to the files chap1 and chap2. 2. to make several permission changes at once, enter: chmod go-w+x mydir
this denies group members and others the permission to create or delete files in mydir (go-w). it allows them to search mydir or use it in a pathname (go+x). this is equivalent to the following command sequence: 3. to permit only the owner to use a shell procedure as a command, enter: chmod u=rwx,go= cmd this gives read, write, and execute permission to the user who owns the file (u=rwx). it also denies the group and others the permission to access cmd in any way (go=).
if you have permission to execute the cmd shell command file, you can run it by entering:
or
4. to use set-id modes, enter: when cmd is executed, this causes the effective user and group ids to be set to those that own the file cmd. only the effective ids associated with the subprocess that runs cmd are changed. the effective ids of the shell session remain unchanged. this feature allows you to permit restricted access to important files. suppose that the file cmd has the set-user-id mode enabled and is owned by a user called dbms. although dbms is not actually a person, it might be associated with a database management system. the user betty does not have permission to access any of dbms's data files. however, she does have permission to execute cmd. when she does so, her effective user id is temporarily changed to dbms, so that the cmd program can access the data files owned by dbms. this way betty can use cmd to access the data files, but she cannot accidentally damage them with the standard shell commands. 5. to use the absolute mode form of the chmod command, enter: chmod 644 text this sets read and write permission for the owner, and it sets readonly mode for the group and all others. commands: chgrp(1), chown(1), csh(1), ksh(1), ls(1), sh(1). functions: chown(2), chmod(2), stat(2), umask(2). delim off
|