設定はだいたいあってるはずだしwindowsからディレクトリ一覧は見えるのにディレクトリにアクセスできないと思って色々調べてたらSELinuxの設定が足りてませんでした。
そういえばubuntu/debianでしかsambaインストールしたことなかったなと思って…
sambaインストール
# yum install samba
samba設定
だいたいこんな感じでしょう。
(デフォルト設定からプリンタを削除し[share]
を追加、[global]
にntlm auth
を追加)
[global] workgroup = SAMBA security = user passdb backend = tdbsam ntlm auth = yes [homes] comment = Home Directories valid users = %S, %D%w%S browseable = No read only = No inherit acls = Yes [share] comment = share directory path = /share create mask = 644 directory mask = 755 writeable = yes valid users = zaki
ntlm auth
については1年半くらい前にubuntu 18.04のsambaで認証がうまく行かずに追加したら動いた設定。
ユーザ追加
# pdbedit -a zaki new password: retype new password: : :
サービス起動と有効化
# systemctl start smb.service # systemctl start nmb.service
2/18追記: リブート後も起動させるために有効化
# systemctl enable smb # systemctl enable nmb
firewall設定
# firewall-cmd --permanent --zone=public --add-service=samba # firewall-cmd --reload
--zone
については環境にあわせる。
SELinux設定
上記はubuntuのときの手順通りで、SELinuxが動いてないなら以下は設定しなくてもアクセスできるはず。
でもSELinuxがenforcingだと追加設定が必要でした。
設定していないと↓のように、(ディレクトリ一覧は見えるのに)アクセスできない状態になった。
ネットワーク管理者氏~~~ #久しぶりのsambaインストール pic.twitter.com/bRb7ch8NXa
— z a k i (@zaki_hmkc) 2020年2月17日
homeディレクトリ
# setsebool -P samba_enable_home_dirs on
共有ディレクトリ
# semanage fcontext -a -t samba_share_t /share # restorecon -R /share/
ちなみに、chcon -t samba_share_t /share
で一時的にコンテキスト設定は変更できるけど、restorecon
でもとに戻るので、semanage fcontext
を使うのが良いとのことです!
semanage fcontext 〜 して
— すぎむら46 (@sugitk) 2020年2月17日
restorecon するのがよいようです。
chcon は一時的な設定です。
semanage
が無い場合は↓で使えるようになる。
# yum install policycoreutils-python