Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 39 of 46

Lesson: SambaSwitch
โ† Linux Foundations

Network operations

Samba

Share a Linux directory with Windows and other clients using Samba.

Samba is free software that implements the SMB protocol on Linux. SMB is what Windows uses for shared folders, so Samba lets Linux, Windows and macOS exchange files.

Install and configure

Install the samba package. The main file is usually /etc/samba/smb.conf. Add a share at the end:

[projects]
   path = /srv/projects
   valid users = alice
   read only = no

The bracketed word is the share name clients see. path is the directory, valid users limits who may connect, and read only = no allows writing. Shares are read-only by default.

Check the syntax:

$ testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.

Users and permissions

Samba keeps its own password database. The Linux user must already exist:

$ sudo smbpasswd -a alice
New SMB password:
Retype new SMB password:
Added user alice.

The Linux file permissions still apply. If alice cannot write to /srv/projects locally, she cannot write through Samba either.

Restart the service. It is usually smbd on Debian and Ubuntu and smb on Fedora and RHEL:

$ sudo systemctl restart smbd

Allow SMB through the firewall (TCP port 445) for your local network only. On systems with SELinux, the directory also needs a suitable label such as samba_share_t.

Connecting

With the smbclient package:

$ smbclient -L //192.168.1.10 -U alice
$ smbclient //192.168.1.10/projects -U alice

-L lists shares. The second opens a prompt with ls, get and put.

To mount the share, install cifs-utils:

$ sudo mkdir -p /mnt/projects
$ sudo mount -t cifs //192.168.1.10/projects /mnt/projects -o username=alice

From Windows, enter \\192.168.1.10\projects in File Explorer.

Compare the ownership rules in the permissions in depth lab.

Try it

  1. In a test machine, create /srv/projects and give your user ownership.
  2. Add a share, run testparm and set an SMB password.
  3. Connect with smbclient //localhost/projects -U followed by your username.

Check your understanding

Samba

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.