Sambaをインストールする手順を記載します。
Table of Contents
1 sambaのインストール
aptでsambaをインストールします。
$ sudo apt install -y samba
2 pdbedit
pdbeditでsambaへアクセスできるユーザを追加します。このユーザはLinux上に存在するユーザである必要があります。pdbeditで追加しようとするユーザがLinux上に存在しない場合は、useraddで追加しておく必要があります。
$ sudo useradd -m hiroom2
pdbeditでhiroom2というユーザを追加します。
$ sudo pdbedit -a hiroom2 new password: retype new password:
-tオプションは標準出力からパスワードを設定することができます。
$ yes "${PASSWD}" | sudo pdbedit -a hiroom2 -t
3 /etc/samba/smb.confの設定
ここではホームディレクトリと共有ディレクトリのアクセスを可能にする設定について記載します。
設定が完了した後、systemctlでsmbdとnmbdを再起動します。
$ sudo systemctl restart smbd nmbd
3.1 ホームディレクトリ共有
以下の設定では、pdbeditで作成したユーザのホームディレクトリをユーザ個人用にアクセスできるようになります。
$ diff -uprN /etc/samba/smb.conf{.org,}
--- /etc/samba/smb.conf.org 2017-01-12 14:08:47.909344000 +0900
+++ /etc/samba/smb.conf 2017-01-12 14:14:25.065344000 +0900
@@ -190,13 +190,13 @@
# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
-;[homes]
-; comment = Home Directories
-; browseable = no
+[homes]
+ comment = Home Directories
+ browseable = no
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
-; read only = yes
+ read only = no
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
@@ -211,7 +211,7 @@
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
-; valid users = %S
+ valid users = %S
# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
3.2 全ユーザ共有ディレクトリ
以下の設定では、pdbeditで追加したユーザでディレクトリを共有できます。
$ diff -uprN /etc/samba/smb.conf{.org,}
--- /etc/samba/smb.conf.org 2016-05-10 09:38:31.909847328 +0900
+++ /etc/samba/smb.conf 2016-05-10 09:46:25.758629642 +0900
@@ -187,6 +187,14 @@
#======================= Share Definitions =======================
+[share]
+ comment = Share directory
+ path = /var/lib/share
+ read only = no
+ guest only = no
+ guest ok = no
+ share modes = yes
+
# Un-comment the following (and tweak the other settings below to
# suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
共有ディレクトリのアクセス権は0777にします。
$ sudo mkdir /var/lib/share $ sudo chmod 0777 /var/lib/share