新年明けて何もしてなかったのですが、NASのシステムディスクが壊れ始めたので、再構築してました。
Blogとかでメモに残してるものが多いので、やり直すのは苦じゃないんですが、Samba関連は書いてなかったなーと思って。
で、案の定、SELinuxの問題で何度も何度も躓いたので、今後の自分のために手順化しておく。
前提
- ソースからのビルドはうまくいかなかったので、yumを使う
- /nas1 というディレクトリを作り、この配下にこんな感じで共有でぃれくとりを作る
- /nas1/public ... パスワード制限なし
- /nas1/share ... パスワード制限あり
Samba用共有グループ作成(share)
groupadd share
既存ユーザ(ryozi)に共有グループ(share)に参加させる
usermod -G share ryozi
Sambaインストール
yum install -y samba
Samba設定(いろんなページを見ながら適当に書いたので、余計な設定とかありそう)
vi /etc/samba/smb.conf
[global] unix charset = UTF-8 dos charset = CP932 display charset = UTF-8 socket options = TCP_NODELAY SO_RCVBUF=16384 SO_SNDBUF=16384 workgroup = WORKGROUP username map = /etc/samba/smbusers smb passwd file = /etc/samba/smbpasswd server string = Nimono Samba Server security = user encrypt passwords = true os level = 0 dns proxy = no hosts allow = 192.168.0. 192.168.1. 127. load printers = no disable spoolss = yes log file = /var/log/samba/log.%m max log size = 1024 dns proxy = no map to guest = Bad User guest account = nobody guest ok = No netbios name = NimonoNAS smb ports = 139 kernel change notify = no printing = bsd printcap cache time = 0 socket address = 192.168.0.XXX [public] comment = All User shared Directories path = /nas1/public guest only = yes guest ok = yes read only = no force create mode = 0666 force directory mode = 0777 printable = no vfs objects = recycle dos filetimes = yes recycle:repository = .recycle recycle:keeptree = no recycle:versions = yes recycle:touch = no recycle:maxsize = 0 recycle:exclude = *.tmp ~$* [share] comment = User Shared Directories path = /nas1/share public = no valid users = @share read list = @share write list = @share read only = no force group = share force create mode = 0660 force directory mode = 0770 printable = no vfs objects = recycle dos filetimes = yes recycle:repository = .recycle recycle:keeptree = no recycle:versions = yes recycle:touch = no recycle:maxsize = 0 recycle:exclude = *.tmp ~$*
Samba関連サービス自動起動設定
chkconfig smb on chkconfig nmb on
Samba関連サービス起動
service smb start service nmb start
Samba用ユーザの追加とパスワード発行
smbpasswd -a ryozi
New SMB password:
Retype new SMB password:
Added user ryozi.
Windowsのユーザとlinuxのユーザをマッピングする場合は、/etc/samba/smbusersも編集する必要があるかもしれない。
また、SELinux絡みのトラブルでよくある(注:当社比)のが、ディレクトリにアクセスできない事。
エラーログをみると、権限がないとだけ出るので、何度もパーミッションを見るけど、実際はSELinuxで弾いてたっていう。
基本的にはそれを読み取るための権限を与えるようにする必要がある。
# 指定したディレクトリとその配下のファイルに読み書き権限を与える(共有ディレクトリ、ログ出力先ディレクトリ含む) chcon -t public_content_rw_t /nas1/public -R chcon -t public_content_rw_t /nas1/share -R # Sambaが使う匿名ユーザの書き込み権限とかをいじるフラグ setsebool -P allow_smbd_anon_write on
もしくは設定ファイルにも書いてあるこっちを使う。
ただ、こっちのやり方はsambaサービス実行ユーザでどこでも好き勝手に読み書きできるようになってしまうっぽい。
でもユーザ単位の共有とか使うならこっちにしないと面倒かも。
# Sambaの読み書き権限を有効 setsebool -P samba_export_all_rw on