권한 비트
-rwxr-xr-- 1 user group filename
├─┤├─┤├─┤
│ │ └── Other users (other)
│ └───── Group (group)
└───────── Owner (user/owner)| 캐릭터 | 번호 | 의미 |
|---|---|---|
r | 4 | 읽기 |
w | 2 | 쓰기 |
x | 1 | 실행(디렉토리의 경우 입력) |
- | 0 | 허가 없음 |
공통 허가 번호
| 번호 | 허가 | 설명 |
|---|---|---|
777 | rwxrwxrwx | 모든 사람을 위한 전체 권한(주의해서 사용) |
755 | rwxr-xr-x | 소유자에게는 전체, 다른 사람에게는 읽기+실행 |
750 | rwxr-x--- | 소유자는 전체, 그룹은 읽기+실행 |
700 | rwx------ | 소유자에게만 가득 |
644 | rw-r—r— | 소유자는 읽기+쓰기, 다른 사람은 읽기 전용 |
640 | rw-r----- | 소유자는 읽기+쓰기, 그룹은 읽기 전용 |
600 | 으------- | 소유자 전용 읽기+쓰기 |
555 | r-xr-xr-x | 모두를 위한 읽기+실행 |
444 | r—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" >> ~/.bashrcACL 확장 권한
기본 권한이 충분히 유연하지 않은 경우:
# 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