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 = noThe 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 smbdAllow 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=aliceFrom Windows, enter \\192.168.1.10\projects in File Explorer.
Compare the ownership rules in the permissions in depth lab.
Try it
- In a test machine, create
/srv/projectsand give your user ownership. - Add a share, run
testparmand set an SMB password. - Connect with
smbclient //localhost/projects -Ufollowed 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.