chmod 명령어 (AIX 5.3·6.1)

핵심 정리

  • 파일이나 디렉터리의 권한 비트(모드)와 확장 ACL을 바꿉니다. 파일 소유자나 root만 바꿀 수 있습니다.
  • 기호 모드: 누구(u, g, o, a) + 연산(+, -, =) + 권한(r, w, x, X, s, t). 예: chmod g+w, chmod u=rwx,go=.
  • 숫자 모드: 8진수 합. 4000(setuid), 2000(setgid), 1000(스티키), 400·200·100(소유자 rwx), 40·20·10(그룹), 4·2·1(다른 사용자). 예: chmod 644, chmod 755.
  • 숫자 모드로 지정하면 확장 ACL이 모두 없어집니다.
  • -R은 재귀로, -h는 심볼릭 링크가 가리키는 대상을 바꾸지 않게, -f는 오류 보고를 줄입니다.
  • 디렉터리에서 setgid를 빼려면 기호 모드나 앞에 0을 붙인 4자리 8진수(예: 0755)를 씁니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 AIXC가 아닌 ACL에 대한 참고와 RBAC 보안 문단이 더해짐)
원문 IBM Commands Reference — 5.3 Volume 1, 6.1 Volume 1
파일 /usr/bin/chmod
관련 명령어 ls, aclget, aclput, chown, chgrp, umask

목적

파일 모드를 바꿉니다.

영어 원문

Changes file modes.

구문

기호로 모드를 바꿀 때:

text
chmod [ -R ] [ -h ] [ -f ] [ [ u ] [ g ] [ o ] | [ a ] ] { { - | + | = } [ r ] [ w ] [ x ] [ X ] [ s ] [ t ] }
      { File ... | Directory ... }

숫자로 모드를 바꿀 때:

text
chmod [ -R ] [ -h ] [ -f ] PermissionCode { File ... | Directory ... }

설명

chmod 명령은 지정한 파일이나 디렉터리의 모드 비트와 확장 접근 제어 목록(ACL)을 바꿉니다. 모드는 기호로, 또는 숫자로(절대 모드) 정할 수 있습니다.

심볼릭 링크를 만났을 때 -h 플래그가 없으면, 링크 자체가 아니라 링크가 가리키는 파일이나 디렉터리의 모드를 바꿉니다. -h를 지정하면 이 변경을 막습니다.

-h와 -R을 함께 지정하면 지정한 디렉터리를 재귀적으로 내려가며, 심볼릭 링크를 만나도 링크가 가리키는 파일이나 디렉터리의 모드는 바꾸지 않습니다.

영어 원문

The chmod command modifies the mode bits and the extended access control lists (ACLs) of the specified files or directories. The mode can be defined symbolically or numerically (absolute mode).

When a symbolic link is encountered and you have not specified the -h flag, the chmod command changes the mode of the file or directory pointed to by the link and not the mode of the link itself. If you specify the -h flag, the chmod command prevents this mode change.

If you specify both the -h flag and the -R flag, the chmod command descends the specified directories recursively, and when a symbolic link is encountered, the mode of the file or directory pointed to by the link is not changed.

플래그

플래그 설명
-f 잘못된 권한과 사용법 메시지를 뺀 모든 오류 보고를 숨깁니다.
-h 만난 심볼릭 링크가 가리키는 파일이나 디렉터리의 모드를 바꾸지 않습니다. 참고: 심볼릭 링크에는 모드 비트를 설정할 수 없으므로 chgrp, chown의 -h와 조금 다르게 동작합니다.
-R File... 또는 Directory... 패턴대로 디렉터리만 재귀적으로 내려갑니다. 각 디렉터리와 패턴에 맞는 모든 파일의 모드 비트를 바꿉니다(예제 6 참고). 디렉터리를 가리키는 심볼릭 링크를 만나면 그 디렉터리의 모드 비트는 바꾸지만 더 내려가지는 않습니다.

기호 모드

기호로 모드를 지정하려면 세 묶음의 글자를 띄우지 않고 이어 씁니다.

첫째 묶음은 누구에게 권한을 주거나 뺄지 정합니다.

글자 대상
u 파일 소유자
g 그룹, 그리고 파일의 그룹에 해당하는 확장 ACL 항목
o 그 밖의 모든 사용자
a 사용자, 그룹, 그 밖의 모든 사용자. ugo를 함께 지정한 것과 같습니다. 아무것도 지정하지 않으면 a가 기본이며, 파일 생성 마스크(umask)가 적용됩니다.

둘째 묶음은 권한을 뺄지, 더할지, 정할지 정합니다.

글자 뜻
- 지정한 권한을 뺍니다.
+ 지정한 권한을 더합니다.
= 고른 권한 자리를 비우고 지정한 권한으로 정합니다. = 뒤에 권한을 쓰지 않으면 고른 자리의 권한을 모두 뺍니다.

셋째 묶음은 빼거나 더하거나 정할 권한입니다.

글자 권한
r 읽기
w 쓰기
x 파일은 실행, 디렉터리는 검색
X 파일은 현재(바꾸기 전) 모드에 사용자·그룹·다른 사용자 실행 비트가 하나라도 있으면 실행 권한. 실행 비트가 하나도 없는 파일에는 무시합니다. 디렉터리는 검색 권한
s u를 지정했거나 포함하면 실행 시 사용자 ID 설정(setuid), g를 지정했거나 포함하면 실행 시 그룹 ID 설정(setgid)
t 디렉터리는 파일 소유자만 그 안의 파일을 링크하거나 지울 수 있게 함(스티키). 파일은 save-text 속성을 설정

숫자(절대) 모드

모드를 8진수로 쓸 수도 있습니다. 숫자 모드는 다음 값 중 하나 이상의 합입니다.

값 뜻
4000 실행 시 사용자 ID 설정
2000 실행 시 그룹 ID 설정
1000 디렉터리에 링크 권한 설정, 파일에 save-text 속성 설정
0400 소유자 읽기
0200 소유자 쓰기
0100 소유자 실행·검색
0040 그룹 읽기
0020 그룹 쓰기
0010 그룹 실행·검색
0004 다른 사용자 읽기
0002 다른 사용자 쓰기
0001 다른 사용자 실행·검색

참고:

  1. 모드를 숫자로 지정하면 확장 ACL이 모두 꺼집니다.
  2. 그룹 권한을 기호로 바꾸면 AIXC ACL 항목에도 영향이 있습니다. ACL에서 파일의 소유 그룹과 같은 그룹 항목은 모드에서 뺀 권한을 거부당합니다(5.3 문서는 "extended ACL"이라고 씀).
  3. 기호 모드는 쉼표로 나눠 여러 개 쓸 수 있으며, 왼쪽부터 차례로 적용합니다.
  4. 디렉터리에서 실행 시 그룹 ID 설정 권한을 빼려면 기호로 지정하거나, 앞에 0을 붙인 4자리 8진수(예: 0755)로 명시해야 합니다.
  5. AIXC가 아닌 ACL(예: NFS4)이 붙은 객체에서 기본 권한 비트(rwxrwxrwx)를 바꾸는 요청을 하면(기호든 숫자든) 기존 ACL이 모드 비트만으로 바뀝니다. 이 항목은 6.1 문서에만 있습니다.
영어 원문
  • -f — Suppresses all error reporting except invalid permissions and usage statements.
  • -h — Suppresses a mode change for the file or directory pointed to by the encountered symbolic link. Note: This behavior is slightly different from the behavior of the -h flag on the chgrp and chown commands because mode bits cannot be set on symbolic links.
  • -R — Descends only directories recursively, as specified by the pattern File...|Directory.... The -R flag changes the file mode bits of each directory and of all files matching the specified pattern. See Example 6. When a symbolic link is encountered and the link points to a directory, the file mode bits of that directory are changed but the directory is not further traversed.
  • Symbolic Mode

To specify a mode in symbolic form, you must specify three sets of flags.

Note: Do not separate flags with spaces.

The first set of flags specifies who is granted or denied the specified permissions, as follows:

  • u — File owner.
  • g — Group and extended ACL entries pertaining to the file's group.
  • o — All others.
  • a — User, group, and all others. The a flag has the same effect as specifying the ugo flags together. If none of these flags are specified, the default is the a flag and the file creation mask (umask) is applied.

The second set of flags specifies whether the permissions are to be removed, applied, or set:

  • - — Removes specified permissions.
  • + — Applies specified permissions.
  • = — Clears the selected permission field and sets it to the permission specified. If you do not specify a permission following =, the chmod command removes all permissions from the selected field.

The third set of flags specifies the permissions that are to be removed, applied, or set:

  • r — Read permission.
  • w — Write permission.
  • x — Execute permission for files; search permission for directories.
  • X — Execute permission for files if the current (unmodified) mode bits have at least one of the user, group, or other execute bits set. The X flag is ignored if the File parameter is specified and none of the execute bits are set in the current mode bits. Search permission for directories.
  • s — Set-user-ID-on-execution permission if the u flag is specified or implied. Set-group-ID-on-execution permission if the g flag is specified or implied.
  • t — For directories, indicates that only file owners can link or unlink files in the specified directory. For files, sets the save-text attribute.
  • Numeric or Absolute Mode

The chmod command also permits you to use octal notation for the mode. The numeric mode is the sum of one or more of the following values:

  • 4000 — Sets user ID on execution.
  • 2000 — Sets group ID on execution.
  • 1000 — Sets the link permission to directories or sets the save-text attribute for files.
  • 0400 — Permits read by owner.
  • 0200 — Permits write by owner.
  • 0100 — Permits execute or search by owner.
  • 0040 — Permits read by group.
  • 0020 — Permits write by group.
  • 0010 — Permits execute or search by group.
  • 0004 — Permits read by others.
  • 0002 — Permits write by others.
  • 0001 — Permits execute or search by others.
  • Notes:
  1. Specifying the mode numerically disables any extended ACLs. Refer to "Access control Lists" in Operating system and device management for more information.

  2. Changing group access permissions symbolically also affects the AIXC ACL entries. The group entries in the ACL that are equal to the owning group of the file are denied any permission that is removed from the mode. Refer to "Access control Lists" in Operating system and device management for more information.

  3. You can specify multiple symbolic modes separated with commas. Operations are performed in the order they appear from left to right.

  4. You must specify the mode symbolically or use an explicit 4-character octal with a leading zero (for example, 0755) when removing the set-group-ID-on-execution permission from directories.

  5. For a non-AIXC ACL associated file system object, any request (either symbolically or numerically) that results in a operation to change the base permissions bits (rwxrwxrwx) in mode bits results in replacement of the existing ACL with just the mode bits.

종료 상태

값 뜻
0 잘 실행했고 요청한 변경을 모두 했습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — The command executed successfully and all requested changes were made.
  • >0 — An error occurred.

보안

접근 제어

이 프로그램은 TCB(Trusted Computing Base)에 일반 사용자 프로그램으로 설치해야 합니다.

파일의 모드는 파일 소유자나 root 사용자만 바꿀 수 있습니다.

RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 이 명령에 걸린 특권과 권한(authorization) 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다. 이 문단은 6.1 문서에만 있습니다.

영어 원문

Access Control

This program should be installed as a normal user program in the Trusted Computing Base.

Only the owner of the file or the root user can change the mode of a file.

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

예제

  1. 여러 파일에 한 가지 권한을 더합니다. chap1과 chap2에 그룹 구성원의 쓰기 권한을 더합니다.
bash
chmod g+w chap1 chap2
  1. 권한 여러 개를 한 번에 바꿉니다. 그룹 구성원과 다른 사용자가 mydir에 파일을 만들거나 지우지 못하게 하고(go-w), mydir을 검색하거나 경로에 쓸 수 있게 합니다(go+x).
bash
chmod go-w+x mydir

다음 명령을 차례로 실행한 것과 같습니다.

bash
chmod g-w mydir
chmod o-w mydir
chmod g+x mydir
chmod o+x mydir
  1. 셸 프로시저를 소유자만 명령으로 쓰게 합니다. 파일 소유자에게 읽기·쓰기·실행 권한을 주고(u=rwx), 그룹과 다른 사용자는 어떤 접근도 못 하게 합니다(go=). cmd 셸 명령 파일의 실행 권한이 있으면 cmd로 실행할 수 있으며, PATH 셸 변수에 따라 전체 경로가 필요할 수 있습니다.
bash
chmod u=rwx,go= cmd
  1. set-ID 모드를 씁니다. cmd를 실행하면 실효 사용자·그룹 ID가 cmd 파일의 소유자 것으로 바뀝니다. 바뀌는 것은 cmd를 실행하는 자식 프로세스의 실효 ID뿐이고, 셸 세션의 실효 ID는 그대로입니다.
bash
chmod ug+s cmd

이 기능으로 제한된 파일에 접근을 허용할 수 있습니다. 예를 들어 cmd 프로그램에 set-user-ID 모드가 켜져 있고 소유자가 dbms라는 사용자(사람이 아니라 데이터베이스 관리 시스템용 계정)라고 합시다. 사용자 betty는 dbms의 데이터 파일에 접근할 권한이 없지만 cmd를 실행할 권한은 있습니다. cmd를 실행하면 실효 사용자 ID가 잠시 dbms로 바뀌어 cmd가 dbms의 데이터 파일에 접근할 수 있습니다. 이렇게 betty는 cmd로 데이터 파일을 쓸 수 있지만, 일반 셸 명령으로 실수로 망가뜨릴 수는 없습니다.

  1. 절대 모드로 지정합니다. 소유자에게 읽기·쓰기, 그룹과 다른 사용자에게 읽기만 줍니다. 파일에 붙어 있던 확장 ACL도 모두 없어집니다.
bash
chmod 644 text
  1. 디렉터리를 재귀적으로 내려가며 파일과 디렉터리 권한을 바꿉니다. 트리가 다음과 같을 때,
text
./dir1/dir2/file1
./dir1/dir2/file2
./dir1/file1

./dir1에서 다음 명령은 ./dir1/file1의 권한을 바꿉니다.

bash
chmod -R 777 f*

트리가 다음과 같으면,

text
./dir1/fdir2/file1
./dir1/fdir2/file2
./dir1/file3

같은 명령이 ./dir1/fdir2, ./dir1/fdir2/file1, ./dir1/fdir2/file2, ./dir1/file3의 권한을 바꿉니다. f*와 맞는 이름만 대상이 되고, 맞는 디렉터리 안으로는 내려가 모두 바꿉니다.

영어 원문
  1. To add a type of permission to several files: chmod g+w chap1 chap2

This adds write permission for group members to the files chap1 and chap2.

  1. To make several permission changes at once: chmod go-w+x mydir

This denies group members and others the permission to create or delete files in mydir (go-w) and allows group members and others to search mydir or use it in a path name (go+x). This is equivalent to the command sequence: chmod g-w mydir chmod o-w mydir chmod g+x mydir chmod o+x mydir

  1. To permit only the owner to use a shell procedure as a command: 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, then you can run it by entering: cmd

Note: Depending on the PATH shell variable, you may need to specify the full path to the cmd file.

  1. To use Set-ID Modes: chmod ug+s cmd

When the cmd command is executed, the effective user and group IDs are set to those that own the cmd file. Only the effective IDs associated with the child process that runs the cmd command are changed. The effective IDs of the shell session remain unchanged. This feature allows you to permit access to restricted files. Suppose that the cmd program has the Set-User-ID Mode enabled and is owned by a user called dbms. The user dbms is not actually a person,

but 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 the cmd command. 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 the user dbms. This way the user betty can use the cmd command to access the data files, but she cannot accidentally damage them with the standard shell commands.

  1. To use the absolute mode form of the chmod command:
chmod 644 text

This sets read and write permission for the owner, and it sets read-only mode for the group and others. This also removes all extended ACLs that might be associated with the file.

  1. To recursively descend directories and change file and directory permissions given the tree structure: ./dir1/dir2/file1 ./dir1/dir2/file2 ./dir1/file1 enter this command sequence:
chmod -R 777 f*

which will change permissions on ./dir1/file1. But given the tree structure of: ./dir1/fdir2/file1 ./dir1/fdir2/file2 ./dir1/file3 the command sequence:

chmod -R 777 f*

will change permissions on: ./dir1/fdir2 ./dir1/fdir2/file1 ./dir1/fdir2/file2 ./dir1/file3

파일

파일 설명
/usr/bin/chmod chmod 명령이 들어 있습니다.

관련 명령어: aclget, ls

영어 원문
  • /usr/bin/chmod — Contains the chmod command .

Related reference:

  • aclget Command

Related information:

  • ls command
  • chmod command
  • AIX Version 7.1 Security
  • Installing and Configuring the Trusted Computing Base

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU chmod
ACL 숫자 모드는 확장 ACL을 모두 지움, 기호 모드는 AIXC ACL 그룹 항목에도 영향 POSIX ACL의 마스크가 바뀜
-h 링크가 가리키는 대상을 바꾸지 않음 없음(리눅스는 심볼릭 링크 권한을 쓰지 않음)
-f 오류 보고 줄이기 같음(--silent)

AIX 5.3·6.1 문서에는 -v, -c(바뀐 것만 보고), --reference=파일 같은 GNU 플래그가 없습니다.