Skip to Content

一般的な権限エラー

「許可が拒否されました」

# View file permissions ls -la /path/to/file # View current user and groups id

「操作は許可されていません」

通常、root 権限が必要です。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

Web サーバーのディレクトリ権限

# 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 0

SSHキーの権限

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 in

sudoパスワードを忘れました

パスワードを忘れた場合は、リカバリ モードでパスワードをリセットします。

  1. GRUB メニュー > 詳細オプション > リカバリモード
  2. ルートコマンドラインを選択します
  3. 実行: 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/directory

ACL 拡張アクセス許可

# 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/file

AppArmor の制限事項

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

トラブルシューティングの概要

  1. ls -la を使用して、ファイルの所有者、グループ、およびアクセス許可ビットを確認します。
  2. id を使用して現在のユーザー ID を確認します
  3. ユーザーが必要なグループに属しているかどうかを確認します: groups USERNAME
  4. AppArmor または SELinux に制限があるかどうかを確認する
  5. マウント オプションを確認します (特に外部パーティションの場合)