zaki work log

作業ログやら生活ログやらなんやら

CentOS7にsamba4.9を入れるときのSELinuxの設定

設定はだいたいあってるはずだし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で認証がうまく行かずに追加したら動いた設定。

forums.ubuntulinux.jp

ユーザ追加

# 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だと追加設定が必要でした。
設定していないと↓のように、(ディレクトリ一覧は見えるのに)アクセスできない状態になった。

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が無い場合は↓で使えるようになる。

# yum install policycoreutils-python

参考

access.redhat.com

access.redhat.com

milestone-of-se.nesuke.com

milestone-of-se.nesuke.com