KaliLinux 2017.1: Install Samba for file server

This article will describe installing samba.

1 Install Samba

Install samba with apt.

$ sudo apt install -y samba
$ sudo systemctl enable smbd nmbd

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

Samba provides /home/hiroom2 sharing to hiroom2 added by pdbedit. This /home/hiroom2 can be accessed by hiroom2 only (The following %S is set to hiroom2 when accessing to Samba).

valid users = %S

Home directory is read only by default. Fix "[homes]" section with the following way. If you need to disable it, comment out "[homes]" section all.

$ cd /etc/samba
$ cat <<EOF | sudo patch -p1
--- a/smb.conf.orig    2017-07-21 14:21:22.404000000 +0900
+++ b/smb.conf 2017-07-21 14:21:31.088000000 +0900
@@ -190,7 +190,7 @@

 # 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.
EOF

Access to the following URL from client.

\\<server>\hiroom2

3.2 Share directory with multiple user.

Share permission 0777 directory with multiple user adde by pdbedit.

$ cat <<EOF | sudo tee -a /etc/samba/smb.conf
[share]
   comment = Share directory
   path = /var/lib/share
   read only = no
   guest only = no
   guest ok = no
   share modes = yes
EOF

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

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

Access to the following URL from client.

\\<server>\share