Skip to Content

권한 비트

-rwxr-xr-- 1 user group filename ├─┤├─┤├─┤ │ │ └── Other users (other) │ └───── Group (group) └───────── Owner (user/owner)
캐릭터번호의미
r4읽기
w2쓰기
x1실행(디렉토리의 경우 입력)
-0허가 없음

공통 허가 번호

번호허가설명
777rwxrwxrwx모든 사람을 위한 전체 권한(주의해서 사용)
755rwxr-xr-x소유자에게는 전체, 다른 사람에게는 읽기+실행
750rwxr-x---소유자는 전체, 그룹은 읽기+실행
700rwx------소유자에게만 가득
644rw-r—r—소유자는 읽기+쓰기, 다른 사람은 읽기 전용
640rw-r-----소유자는 읽기+쓰기, 그룹은 읽기 전용
600으-------소유자 전용 읽기+쓰기
555r-xr-xr-x모두를 위한 읽기+실행
444r—r—r—모든 사람에게 읽기 전용

chmod 명령

숫자 모드

chmod 755 filename chmod 644 filename chmod -R 755 directory # Recursive

기호 모드

# Add permissions chmod u+x file # Add execute for owner chmod g+w file # Add write for group chmod o-r file # Remove read for others chmod a+r file # Add read for everyone # Set exact permissions chmod u=rwx,g=rx,o=r file # Common combinations chmod +x script.sh # Add execute permission chmod -w file.txt # Remove write permission

대상: u=소유자, g=그룹, o=기타, a=모두

작업: +=추가, -=제거, ==설정

chown 명령

# Change owner sudo chown username filename # Change owner and group sudo chown username:groupname filename # Change group only sudo chown :groupname filename # Or use chgrp chgrp groupname filename # Recursive sudo chown -R username:groupname directory

특별 허가 비트

SUID(사용자 ID 설정) - 4xxx

파일은 파일을 실행하는 사용자가 아닌 소유자로 실행됩니다.

chmod u+s file chmod 4755 file # Example: passwd command uses SUID ls -la /usr/bin/passwd # -rwsr-xr-x 1 root root ...

SGID(그룹 ID 설정) - 2xxx

디렉터리에 생성된 새 파일은 디렉터리의 그룹을 상속합니다.

chmod g+s directory chmod 2755 directory

끈적한 비트 - 1xxx

파일 소유자만이 디렉터리(예: /tmp) 내에서 파일을 삭제할 수 있습니다.

chmod +t directory chmod 1777 directory ls -la /tmp # drwxrwxrwt ... # Note the trailing t

기본 권한(umask)

# Check current umask umask # Common value: 0022 # umask calculation: # File default permissions = 666 - umask = 644 # Directory default permissions = 777 - umask = 755 # Temporary change umask 027 # Files 640, directories 750 # Permanent change: add to ~/.bashrc echo "umask 027" >> ~/.bashrc

ACL 확장 권한

기본 권한이 충분히 유연하지 않은 경우:

# Install ACL tools sudo apt install acl # Set permissions for a specific user setfacl -m u:username:rwx filename # Set permissions for a specific group setfacl -m g:groupname:rx filename # Set default ACL (new files auto-inherit) setfacl -d -m u:username:rwx directory # View ACL getfacl filename # Remove all ACL setfacl -b filename

사용자 및 그룹 관리

# Check current user info id # Check user's groups groups username # Add user to a group sudo usermod -aG groupname username # Create a new group sudo groupadd groupname # Common system groups # sudo - Administrator privileges # docker - Docker operations # video - Camera/GPU access # audio - Audio devices # dialout - Serial port devices # plugdev - Pluggable devices

공통 시나리오 권한 설정

# Web directory sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html # SSH keys chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa chmod 644 ~/.ssh/id_rsa.pub # Shared directory (group read+write) sudo mkdir /shared sudo chown :shared-group /shared sudo chmod 2775 /shared # Script files chmod 755 script.sh # Everyone can execute chmod 700 script.sh # Only owner can execute