정의
각각 CHange OWNer, CHange MODe 의 약자
파일의 소유자 변경하거나, 파일의 권한를 변경할 때 쓰임
#chown
chown 을 사용하여 파일이나 디렉토리의 소유자를 변경할 수 있음
#chmod
chmod 를 사용하여 파일이나 디렉토리의 권한을 변경할 수 있음
$ stat /bin/ls
File: /bin/ls
Size: 142144 Blocks: 280 IO Block: 4096 regular file
Device: 810h/2064d Inode: 38050 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-11-07 22:08:04.420000000 +0900
Modify: 2019-09-05 19:38:40.000000000 +0900
Change: 2020-06-01 03:00:07.450000000 +090
Birth: -
#위에서 Access의 (0755/-rwxr-xr-x) 가 Permission을 표현함(Read, Write, EXecute의 약자임)
해석하면 아래와 같음

Owner, Group, Other 3 종류지만 0755로 표현됨
=> 이는 특수 권한임
기본 포맷
#chown
chown [OPTIONS] USER[:GROUP] FILE(s)
#chmod
chmod [PERMISSION] [FILE OR DIRECTORY]
용도
#chown
#소유자 변경
chown user /path/to/file_or_directory
#소유자 + 그룹 변경
chown user:group /path/to/file_or_directory
#하위 디렉토리 변경 사항 적용
chown -R www-data:www-data /var/www/html
#symbolic link 변경 사항 적용
chown -h user /path/to/symboli_link
#하위 디렉토리 + 심볼릭 링크 변경 사항 적용
chown -hR user:group /path/to/file_or_dir
#chmod
#권한 변경
chmod +x test.sh
chmod 755 test.sh
chmod 700 ~/.ssh
#문자로 기술할 경우 , 앞뒤에 공백이 있으면 "invalid mode: " 에러가 발생
chmod u+rwx,g=-rwx,o=-rwx ~/.ssh
Option
#chown
OptionDescription
-R | Recursively change ownership of all files and directories within a specified directory. |
--dereference | Affect the referent of each symbolic link instead of the symbolic link itself. |
--no-dereference | Affect only the symbolic links, not any referenced file. |
--from=CURRENT_OWNER | Only change the ownership of files that are currently owned by CURRENT_OWNER. |
--quiet | Suppress error messages about files that cannot be changed. |
--reference=RFILE | Use RFILE's ownership and group rather than specifying UID and GID. |
--from=CURRENT_OWNER:CURRENT_GROUP | Only change the ownership of files that are currently owned by CURRENT_OWNER and CURRENT_GROUP. |
--no-preserve-root | Do not treat '/' (the root directory) specially. By default, chown will not operate recursively on '/' to avoid the possibility of accidentally changing the ownership of the whole file system. |
--preserve-root | Do not operate recursively on '/' (the root directory). This is the default behavior. |
--verbose | Print the name of each file before changing its ownership. |
#chomod
OptionDescription
+rwx | Add read, write, and execute permissions for the owner of the file. |
-rwx | Remove read, write, and execute permissions for the owner of the file. |
+x | Add execute permission for the owner of the file. |
-x | Remove execute permission for the owner of the file. |
+r | Add read permission for the owner of the file. |
-r | Remove read permission for the owner of the file. |
+w | Add write permission for the owner of the file. |
-w | Remove write permission for the owner of the file. |
+rw | Add read and write permission for the owner of the file. |
-rw | Remove read and write permission for the owner of the file. |
+rwx,g | Add read, write, and execute permissions for the group of the file. |
+rwx,o | Add read, write, and execute permissions for others. |
+rwx,a | Add read, write, and execute permissions for all (owner, group, and others). |
755 | Set read, write, and execute permissions for the owner and read and execute permissions for the group and others. |
644 | Set read and write permissions for the owner and read permissions for the group and others. |
참고링크
https://phoenixnap.com/kb/linux-chown-command-with-examples
https://linuxize.com/post/linux-chown-command/
https://www.lesstif.com/lpt/linux-chown-93127453.html
https://jjeongil.tistory.com/1907
https://www.lesstif.com/lpt/linux-chmod-93127208.html
아래는 IBM QShell 이지만 참고
https://www.ibm.com/docs/ko/i/7.3?topic=directories-chgrp