1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linuxで、一部のディレクトリをユーザ間で共有する

Last updated at Posted at 2019-05-02

Linuxで、一部のディレクトリのみ、特定のユーザ間でファイルを共有し、自由に読み書きできるようにする方法を記載します。
umaskと、ユーザが所属するグループ、set-group-IDビットなどを活用します。

また、samba経由でも、同じディレクトリを、読み書きできるようにします。

Debian 10で動作確認をしています。

1. ローカルユーザでの共有

デフォルトの umask を 0007 にする

/etc/pam.d/common-session に次の行を追加します。

session	optional			pam_umask.so 

/etc/login.defs の UMASK の設定を007に変更します。

UMASK           007

ファイル共有用のグループを追加する

sudo addgroup share

ファイルを共有したいユーザを、追加したグループに所属させる

sudo usermod -a -G "share" user1

共有ディレクトリの所有グループとパーミッションを設定する

chgrp share /var/samba/share
chmod 2770 /var/samba/share

各サービスの umask の設定を行う

Debian 9までは pam の設定のみで効果があったのですが、 Debian 10 ではユーザごとに各サービスの umask の設定が必要なようです。

参考: https://unix.stackexchange.com/questions/254378/how-to-set-umask-for-the-entire-gnome-session/411060#411060

まず、dbus の設定をします。

systemctl --user edit dbus

内容は次のようにします。

[Service]
UMask=007

次に、gnome-terminal-server の設定をします。

systemctl --user edit gnome-terminal-server

同じく、内容は次のようにします。

[Service]
UMask=007

これで、ほとんどのアプリケーションの umask が 0007 になったはずです。

2. sambaでの共有

/etc/samba/smb.conf に以下の内容を追加します。

[share]
	path = /var/samba/share
	read only = No
	create mask = 0660
	directory mask = 0770

systemctl reload smbd を実行します。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?