Linux(Ubuntu)とWindowsで特定のユーザー権限でフォルダ共有

Sambaサーバー側での作業

パッケージインストール

$ sudo apt-get install samba

sambaの設定ファイルを編集。以下を追加

$ vi /etc/samba/smb.conf

[global]

#map to guest = bad user   #Linux に存在しないユーザーでのアクセスはゲストとして扱う
hosts allow = 192.168.0.0/24

# ユーザー名とパスワードでローカル認証を行う設定
security = user
# ファイル作成時のパーミッション
create mask = 0777
force create mode = 0644
security mask = 0777
force security mode = 0644

# ディレクトリ作成時のパーミッション
directory mask = 0777
force directory mode = 0755
directory security mask = 0777
force directory security mode = 0755


[Share]
  path = /mnt/share
  guest ok = no
  writeable = yes
  browseable = yes
  valid users = @www-data
  create mode = 0644
  directory mode = 0755

設定ファイルのエラーチェック

# testparm /etc/samba/smb.conf
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[printers]"
Processing section "[print$]"
Processing section "[Share]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

共有フォルダアクセス用のユーザを作成。www-dataで作成

# useradd www-data
useradd: user 'www-data' already exists #apache入れてるので既にいる
# smbpasswd -a www-data
New SMB password:
Retype new SMB password:
Added user www-data.
# pdbedit -L
www-data:33:www-data

sambaサービスを再起動

# service smbd restart

windows側作業

  1. 「フォルダ」→ 「PC」を右クリック
  2. 「ネットワークドライブの割り当て」を選択
  3. \IPアドレス\Share を入力して接続

これで、www-dataユーザーでsambaに接続できます