グループにディレクトリへの読み取り/書き込みアクセスを許可する

グループにディレクトリへの読み取り/書き込みアクセスを許可する

ユーザー 1 とユーザー 2 の 2 人のユーザーがいて、どちらもグループ A のメンバーです。ユーザー 2 のホーム ディレクトリには、folderA というフォルダーがあります。グループ A のすべてのメンバーに読み取り、書き込み、実行の権限を許可したい場合は、どうすればよいでしょうか。

フォルダー A に、読み取り、書き込み、実行権限も必要な多くのファイルと追加のフォルダーが含まれている場合はどうなりますか?

グループに関する情報はウェブ上で少し「ばらつき」があるため、誰かが明確な回答を投稿して他の人にも役立つことを期待して、ここに質問を投稿します。

ありがとう!

答え1

フォルダAまず参加する必要があるグループA- フォルダの所有者またはルートがこの操作を実行できます

chgrp groupA ./folderA

それからグループAフォルダのrwx権限が必要になります

chmod g+rwx  ./folderA

必要に応じてディレクトリを再帰的に検索するためのオプションが コマンドchgrpとコマンドにあります。chmod

答え2

この分野での私の経験はここにあります。Ubuntu 18.04 でテスト済みです。

システムフォルダへの書き込みを許可する

/etc/nginx/フォルダーへの書き込み権限を与えます。

# Check 'webmasters' group doen't exist
cat /etc/group | grep webmasters
# Create 'webmasters' group
sudo addgroup webmasters
# Add users to 'webmasters' group
sudo usermod -a -G webmasters username
sudo usermod -a -G webmasters vozman
sudo usermod -a -G webmasters romanroskach

# Group assignment changes won't take effect
# until the users log out and back in.

# Create directory
sudo mkdir /etc/nginx/
# Check directory permissions
ls -al /etc | grep nginx
drwxr-xr-x   2 root root     4096 Dec  5 18:30 nginx

# Change group owner of the directory
sudo chgrp -R webmasters /etc/nginx/
# Check that the group owner is changed
ls -al /etc | grep nginx
drwxr-xr-x   2 root webmasters   4096 Dec  5 18:30 nginx

# Give write permission to the group
sudo chmod -R g+w /etc/nginx/
# Check
ls -al /etc | grep nginx
drwxrwxr-x   2 root webmasters   4096 Dec  5 18:30 nginx

# Try to create file
sudo -u username touch /etc/nginx/test.txt  # should work
sudo -u username touch /etc/test.txt  # Permission denied

/etc/systemd/system/フォルダーへの書き込み権限を与えます。

# List ACLs
getfacl /etc/systemd/system

getfacl: Removing leading '/' from absolute path names
# file: etc/systemd/system
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

# Add 'webmasters' group to an ACL
sudo setfacl -m g:webmasters:rwx /etc/systemd/system

# Check
getfacl /etc/systemd/system

getfacl: Removing leading '/' from absolute path names
# file: etc/systemd/system
# owner: root
# group: root
user::rwx
group::r-x
group:webmasters:rwx
mask::rwx
other::r-x

sudo -u username touch /etc/systemd/system/test.txt  # should work
sudo -u username touch /etc/systemd/test.txt  # Permission denied

オリジナルのハウツー

関連情報