CentOS7にSambaサーバーをインストールする
スポンサーリンク
SELinuxの無効化
有効になっている場合,共有ディレクトリにアクセスできない
$ sudo vi /etc/selinux/config $ reboot $ getenforce Disabled
Sambaのインストール
$ sudo yum -y install samba samba-client
ファイアウォールの設定
$ sudo firewall-cmd --permanent --add-service=samba $ sudo systemctl restart firewalld $ sudo firewall-cmd --list-service dhcpv6-client samba ssh
Samba起動モードの設定
$ sudo vi /etc/sysconfig/samba SMBDOPTIONS="-D" NMBDOPTIONS="-D"
設定ファイルの編集
$ sudo vi /etc/samba/smb.conf ... [global] unix charset = UTF-8 dos charset = CP932 writable = yes guest ok = no vfs objects = recycle recycle:repository = .recycle recycle:keeptree = no recycle:touch = yes recycle:versions = yes recycle:maxsize = 0 # ----------------------- Network-Related Options ------------------------- ... workgroup = WORKGROUP server string = Samba Server Version %v ; netbios name = MYSERVER ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 # 192.168.1.を自分のネットワークに変更する hosts allow = 127. 192.168.1. ; max protocol = SMB2 ... # ----------------------- Standalone Server Options ------------------------ security = user ... # --------------------------- Printing Options ----------------------------- load printers = no ...
共有ディレクトリの追加
$ sudo vi /etc/samba/smb.conf (ファイル末尾) [share] path = /path/to/share
ファイル作成時のアクセス権の設定を行う場合は
create mask = 0640 directory mask = 0640 force create mode = 0640 force directory mode = 0640
などを追加する
- create/directory mask 作成したファイル/ディレクトリと指定したアクセス権でAND演算を行った結果が付与されるアクセス権になる
- force create/directory mode 作成したファイル/ディレクトリがすべて指定したアクセス権になる
Samba起動・自動起動
$ sudo systemctl start smb $ sudo systemctl start nmb $ sudo systemctl enable smb $ sudo systemctl enable nmb
Samba用のユーザー作成
$ sudo smbpasswd -a ${USER_NAME} New SMB password: Retype new SMB password: Added user ${USER_NAME}.
追記
追記1: アクセスが遅い場合
サーバ側のHDDマウントオプションにnoatime
を追加し,最終アクセス時間(atime
)を記録しないようにする
$ sudo vi /etc/fstab ... DISK /MOUNT/POINT ext4 defaults,noatime 0 0
追記2: Unable to connect to CUPS serverが出る
ログファイル(/var/log/samba/log.smbd
)に以下のエラーが出力される場合は
Unable to connect to CUPS server localhost:631 - 通信端点が接続されていません
以下のように
;printing = cups
を
printing = bsd
に変更する
$ sudo vi /etc/samba/smb.conf # --------------------------- Printing Options ----------------------------- load printers = no cups options = raw ; printcap name = /etc/printcap # obtain a list of printers automatically on UNIX System V systems: ; printcap name = lpstat printing = bsd
追記3: シンボリックリンクリンクへのアクセスを有効化する
[global]
セクションに以下の2行を追加し,sambaを再起動する
$ sudo vi /etc/samba/smb.conf ... [global] ... wide links = yes unix extensions = no