Simple Network Shares With Samba

Samba is a mature, multi platform software package which provides file and print services using the SMB protocol. It can also be used for authentication as a Windows domain controller, and has other administrative tools built in, too. In my case, I'm going to be using Samba to share a folder from a small Linux server (an Asus EeePC in my closet) to the Windows machines on my home network.

For being such a featureful software package, installing and configuring Samba is very straightforward. Before I start to install, I want to be clear on what I'm trying to accomplish: I am creating a single location to store files on a trusted home network, where anyone on the LAN has read/write access. To begin, I'm going to create a new user on the Linux machine who will be running the Samba service-

root@asus-eeepc:/# adduser samba-user
Adding user `samba-user' ...
Adding new group `samba-user' (1002) ...
Adding new user `samba-user' (1002) with group `samba-user' ...
Creating home directory `/home/samba-user' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for samba-user
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n] y

Next, to install-

root@asus-eeepc:/# apt install samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
attr ibverbs-providers libboost-regex1.67.0 libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 librados2 libtirpc-common libtirpc3 python-dnspython
python-gpg python-ldb python-samba python-tdb samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
Suggested packages:
bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools ufw winbind heimdal-clients
The following NEW packages will be installed:
attr ibverbs-providers libboost-regex1.67.0 libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 librados2 libtirpc-common libtirpc3 python-dnspython
python-gpg python-ldb python-samba python-tdb samba samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded.
Inst python-dnspython (1.16.0-1 Debian:10.0/stable [all])
Inst python-ldb (2:1.5.1+really1.4.6-3 Debian:10.0/stable [amd64])
Inst python-tdb (1.3.16-2+b1 Debian:10.0/stable [amd64])
Inst python-samba (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Inst samba-common (2:4.9.5+dfsg-5 Debian:10.0/stable [all])
Inst samba-common-bin (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Inst tdb-tools (1.3.16-2+b1 Debian:10.0/stable [amd64])
Inst samba (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Inst attr (1:2.4.48-4 Debian:10.0/stable [amd64])
Inst libibverbs1 (22.1-1 Debian:10.0/stable [amd64])
Inst ibverbs-providers (22.1-1 Debian:10.0/stable [amd64])
Inst libboost-regex1.67.0 (1.67.0-13 Debian:10.0/stable [amd64])
Inst librados2 (12.2.11+dfsg1-2.1 Debian:10.0/stable [amd64])
Inst libcephfs2 (12.2.11+dfsg1-2.1 Debian:10.0/stable [amd64])
Inst libtirpc-common (1.1.4-0.4 Debian:10.0/stable [all])
Inst libtirpc3 (1.1.4-0.4 Debian:10.0/stable [amd64])
Inst libglusterfs0 (5.5-3 Debian:10.0/stable [amd64])
Inst libgfxdr0 (5.5-3 Debian:10.0/stable [amd64])
Inst libgfrpc0 (5.5-3 Debian:10.0/stable [amd64])
Inst libgfapi0 (5.5-3 Debian:10.0/stable [amd64])
Inst python-gpg (1.12.0-6 Debian:10.0/stable [amd64])
Inst samba-dsdb-modules (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Inst samba-vfs-modules (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Conf python-dnspython (1.16.0-1 Debian:10.0/stable [all])
Conf python-ldb (2:1.5.1+really1.4.6-3 Debian:10.0/stable [amd64])
Conf python-tdb (1.3.16-2+b1 Debian:10.0/stable [amd64])
Conf python-samba (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Conf samba-common (2:4.9.5+dfsg-5 Debian:10.0/stable [all])
Conf samba-common-bin (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Conf tdb-tools (1.3.16-2+b1 Debian:10.0/stable [amd64])
Conf samba (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Conf attr (1:2.4.48-4 Debian:10.0/stable [amd64])
Conf libibverbs1 (22.1-1 Debian:10.0/stable [amd64])
Conf ibverbs-providers (22.1-1 Debian:10.0/stable [amd64])
Conf libboost-regex1.67.0 (1.67.0-13 Debian:10.0/stable [amd64])
Conf librados2 (12.2.11+dfsg1-2.1 Debian:10.0/stable [amd64])
Conf libcephfs2 (12.2.11+dfsg1-2.1 Debian:10.0/stable [amd64])
Conf libtirpc-common (1.1.4-0.4 Debian:10.0/stable [all])
Conf libtirpc3 (1.1.4-0.4 Debian:10.0/stable [amd64])
Conf libglusterfs0 (5.5-3 Debian:10.0/stable [amd64])
Conf libgfxdr0 (5.5-3 Debian:10.0/stable [amd64])
Conf libgfrpc0 (5.5-3 Debian:10.0/stable [amd64])
Conf libgfapi0 (5.5-3 Debian:10.0/stable [amd64])
Conf python-gpg (1.12.0-6 Debian:10.0/stable [amd64])
Conf samba-dsdb-modules (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])
Conf samba-vfs-modules (2:4.9.5+dfsg-5 Debian:10.0/stable [amd64])

I'm going to confirm Samba is running-

root@asus-eeepc:/# service smbd status
● smbd.service - Samba SMB Daemon
Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-08-04 22:44:31 EDT;
Docs:   man:smbd(8)
Process: 13393 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 12798 (smbd)
Status: "smbd: ready to serve connections..."
Tasks: 5 (limit: 4915)
CGroup: /system.slice/smbd.service
├─12798 /usr/sbin/smbd
├─12799 /usr/sbin/smbd
├─12800 /usr/sbin/smbd
├─12802 /usr/sbin/smbd
└─12804 /usr/sbin/smbd

And it is. Using Samba's smbpasswd (similar to passwd), I'm going to add a new user to the service-

root@asus-eeepc:/# smbpasswd -a samba-user

Using Samba's pdbedit, I can manage user accounts stored in Samba's user database. This would be a useful tool for someone managing a larger number of users.

root@asus-eeepc:/# pdbedit -w -L
samba-user:1001:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:0910F7894D10FB3E2C4CF51D09CCE6FB:[U          ]:LCT-5D4C7364:

Now that I've got my user added, I'm going to configure the service itself. Since I've decided that I'm going to be sharing just one folder for everyone, I'm going to create a folder named "asus-eeepc" in samba-user's home directory. Afterwards, I'm going to configure the smbd daemon by editing /etc/samba/smb.conf.

root@asus-eeepc:/# mkdir /home/samba-user/asus-eeepc
root@asus-eeepc:/# cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Just like other mature packages, Samba offers many options to configure in smb.conf. Because my install is fairly simple, I can keep the default values for the majority of the file save for a few minor changes. In the [global] block, I want to confirm that the nt-domain/workgroup specified matches what my samba share will be a part of (I have a default Windows 7 value)-

workgroup = WORKGROUP

By default, the home directory of the Samba user will be shared (which is a surprising default, imo). I'd rather that not be the case, so I need to comment out the entire [homes] block (every line up to the next block).

; [homes]
; ...

Next, I'm going to define my share. Note that if I did not include the 'guest ok = yes' directive, then every time a user wanted to connect he/she would have to enter samba-users user/password.

    path = /home/samba-user/asus-eeepc
    read only = no
    locking = no
    guest ok = yes
    hosts allow = 192.168.
    hosts deny = ALL

After saving my changes, I have to restart the Samba service in order for changes to take effect-

root@asus-eeepc:/# service smbd restart

On my Windows machines, if I've done everything correctly, clicking the start orb and entering the ip address of my Asus EeePC in the run dialogue should open Explorer at the location of my network share-

Location of the network share.

Tags: [System Administration] [Linux] [Samba]

Category: [Blog]