ElementaryOS 0.4: Install samba for SMB server

This article will describe installing samba.

1 Install samba

Install samba with apt.

$ sudo apt install -y samba

2 pdbedit

Add user access to samba with pdbedit. This user must be exists in Linux. If user to be added by pdbedit does not exist, you need to add user with useradd.

$ sudo useradd -m hiroom2

This article adds hiroom2 with pdbedit.

$ sudo pdbedit -a hiroom2
new password:
retype new password:

-t option reads password from stdout.

$ yes "${PASSWD}" | sudo pdbedit -a hiroom2 -t

3 /etc/samba/smb.conf

This article show how to share home directory for each user and share directory with multiple user.

Please reboot smbd and nmbd after editing smb.conf.

$ sudo systemctl restart smbd nmbd

3.1 Share home directory for each user

Share home directory for each user added by 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 Share directory with multiple user.

Share permission 0777 directory with multiple user adde by 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

Change /var/lib/share's permission to 0777.

$ sudo mkdir /var/lib/share
$ sudo chmod 0777 /var/lib/share