일반적인 권한 오류
“권한이 거부되었습니다”
# View file permissions
ls -la /path/to/file
# View current user and groups
id“작업이 허용되지 않습니다”
일반적으로 루트 권한이 필요합니다. sudo을 사용하세요.
sudo COMMAND파일 권한 기본 사항
-rwxr-xr-- 1 user group 4096 Mar 24 10:00 file.txt
|---|---|---|
| | | +-- Other users: r-- (read)
| | +----- Group: r-x (read+execute)
| +--------- Owner: rwx (read+write+execute)
+------------- File type (- regular file, d directory, l symlink)일반적인 시나리오 수정
구성 파일을 편집할 수 없습니다.
# Files in /etc belong to root
sudo nano /etc/xxx/config.conf
# Or temporarily change permissions (not recommended for system files)
sudo chmod 666 /path/to/file스크립트를 실행할 수 없습니다
# Add execute permission
chmod +x script.sh
# Owner only can execute
chmod u+x script.sh웹 서버 디렉토리 권한
# Typical web directory permission setup
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
sudo chmod -R 644 /var/www/html/*.html마운트된 드라이브에 쓸 수 없습니다.
NTFS 또는 FAT32 파티션 권한은 마운트 옵션으로 제어됩니다.
# View current mounts
mount | grep /dev/sd
# Remount NTFS as writable
sudo mount -o rw,uid=$(id -u),gid=$(id -g) /dev/sdX1 /mnt/data
# Configure in /etc/fstab
# UUID=xxx /mnt/data ntfs-3g defaults,uid=1000,gid=1000 0 0SSH 키 권한
SSH에는 키 파일 권한에 대한 엄격한 요구 사항이 있습니다.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/config홈 디렉터리 권한이 변경됨
# Restore home directory permissions
sudo chown -R $USER:$USER ~/
chmod 755 ~/sudo 관련 문제
sudo 그룹에 없는 사용자
# Need to log in as root or use recovery mode
su - root
usermod -aG sudo USERNAME
# User needs to log out and log back insudo 비밀번호를 잊어버렸습니다
비밀번호를 잊어버린 경우 복구 모드를 통해 비밀번호를 재설정하세요.
- GRUB 메뉴 > 고급 옵션 > 복구 모드
- 루트 명령줄 선택
- 실행:
passwd USERNAME
/etc/sudoers 구문 오류로 인해 sudo가 중단됩니다.
# Use pkexec to fix (no sudo needed)
pkexec visudo
# Or fix from recovery mode
# Make sure /etc/sudoers contains:
# %sudo ALL=(ALL:ALL) ALL특별 허가
SUID/SGID/고정 비트
# Set SUID (execute as file owner)
chmod u+s /path/to/file
# Set SGID (new files inherit the directory's group)
chmod g+s /path/to/directory
# Set Sticky Bit (only owner can delete files in the directory)
chmod +t /path/to/directoryACL 확장 권한
# Install ACL tools
sudo apt install acl
# Set permissions for a specific user
setfacl -m u:USERNAME:rwx /path/to/file
# View ACL
getfacl /path/to/file
# Remove ACL
setfacl -b /path/to/fileAppArmor 제한 사항
Ubuntu는 필수 액세스 제어를 위해 AppArmor를 사용합니다.
# View AppArmor status
sudo aa-status
# Temporarily set a program to complain mode
sudo aa-complain /usr/bin/PROGRAM_NAME
# Disable a profile
sudo aa-disable /etc/apparmor.d/PROFILE_NAME문제 해결 요약
ls -la을 사용하여 파일의 소유자, 그룹 및 권한 비트를 확인하세요.id을 사용하여 현재 사용자 신원을 확인하세요.- 사용자가 필수 그룹
groups USERNAME에 속해 있는지 확인하세요. - AppArmor 또는 SELinux에 제한사항이 있는지 확인하세요.
- 마운트 옵션 확인(특히 외부 파티션의 경우)