How to Set Up a Samba Share on Block Storage on Debian 13
Put a Samba file share on a separate block storage volume on Debian 13: format, mount by UUID, configure smb.conf, add users, firewall port 445 and connect from clients.
This guide sets up a password-protected Samba (SMB) file share on Debian 13 whose data lives on a separate block storage volume instead of the system disk. You will format the volume, mount it permanently by UUID, define the share in smb.conf, create Samba users, restrict access with a firewall, and connect from Windows, macOS and Linux. Keeping the share on its own volume means you can grow it, snapshot it or move it to another server without touching the operating system.
Debian 9 reached end of life in 2022. The steps below are written for Debian 13 (Samba 4.22) and work the same way on Debian 12, which ships Samba 4.17.
Requirements
- A server running Debian 13 or Debian 12 and a user with
sudorights. - An additional volume created in your hosting control panel and attached to the server.
- The addresses your clients connect from. The examples allow the network
203.0.113.0/24; the server is198.51.100.10.
Do not offer SMB to the whole internet. Port 445 is scanned constantly and many access providers block it outright. Allow only fixed client addresses, or put a VPN in front and share over the VPN's private addresses.
Step 1: Find and format the volume
List the block devices:
lsblk -fThe new volume is the disk with the size you ordered, no file system and no mount point — typically /dev/vdb or /dev/sdb. The examples use /dev/vdb; replace it with your device name everywhere.
Create an ext4 file system on it. This erases everything on the device, so make sure you picked the right one. Skip this command if the volume already contains data you want to keep.
sudo mkfs.ext4 -L sambadata /dev/vdbStep 2: Mount the volume by UUID
Device names such as /dev/vdb can change when volumes are attached or detached. The UUID of the file system does not, so use it in /etc/fstab. Read it:
sudo blkid -s UUID -o value /dev/vdbCreate the mount point:
sudo mkdir -p /srv/sambaOpen /etc/fstab and add one line, with your own UUID in place of the example value:
sudo nano /etc/fstabUUID=0a1b2c3d-1111-2222-3333-444455556666 /srv/samba ext4 defaults,nofail 0 2nofail lets the server finish booting even when the volume is detached; without it, a missing volume leaves you in emergency mode on the console. Mount everything from fstab and check the result:
sudo systemctl daemon-reload
sudo mount -a
findmnt /srv/samba
df -h /srv/sambafindmnt must show your device as the source. If mount -a prints an error, fix the line before you reboot.
Step 3: Install Samba
sudo apt update
sudo apt install samba smbclientsamba provides the file server daemon smbd; smbclient is a command-line client used for testing in step 7. The service is started and enabled automatically:
systemctl status smbd --no-pagerStep 4: Create the share directory, a group and users
Access is controlled twice: Samba checks the user name and password, and the Linux file permissions decide what that user may do on disk. A dedicated group keeps both simple.
Create the group and the directory on the mounted volume:
sudo groupadd smbshare
sudo mkdir -p /srv/samba/share
sudo chgrp smbshare /srv/samba/share
sudo chmod 2770 /srv/samba/shareMode 2770 gives the owner and the group full access and nobody else any. The leading 2 is the setgid bit: new files and folders inherit the smbshare group, so every member can work with what the others create.
Every Samba user needs a Linux account. These accounts only exist for the share, so create them without a home directory and without a login shell, and put them in the group:
sudo useradd -M -s /usr/sbin/nologin -G smbshare aliceSamba keeps its own password database. Add the user to it and set the share password when prompted:
sudo smbpasswd -a aliceRepeat both commands for each person. To change a password later, run sudo smbpasswd alice; to list the Samba users, run sudo pdbedit -L.
Step 5: Define the share in smb.conf
Keep a copy of the packaged configuration, then open the file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
sudo nano /etc/samba/smb.confAppend this block at the end of the file:
[share]
comment = Team share on block storage
path = /srv/samba/share
valid users = @smbshare
read only = no
browseable = yes
force group = smbshare
create mask = 0660
directory mask = 2770[share]is the name clients see:\\198.51.100.10\share.valid users = @smbshareadmits only members of the group.read only = nopermits writing. Leave it out, or setyes, for a read-only share.create maskanddirectory maskkeep new files private to the group.
As a second line of defence next to the firewall, you can also limit by client address inside Samba. Add this to the same block:
hosts allow = 127.0.0.1 203.0.113.0/24Check the file for mistakes. testparm prints the configuration as Samba understands it and reports unknown or misspelled parameters:
testparm -sApply the change:
sudo systemctl restart smbdStep 6: Open the firewall for your clients only
Current SMB uses TCP port 445 only. The NetBIOS ports 137–139 are needed solely for legacy name resolution and very old clients; leave them closed.
Debian does not enable a firewall by default. If you do not use one yet, ufw is the quickest to set up. Allow SSH before enabling it, or you lock yourself out:
sudo apt install ufw
sudo ufw allow OpenSSH
sudo ufw allow from 203.0.113.0/24 to any port 445 proto tcp
sudo ufw enable
sudo ufw statusIf your provider has a network-level firewall in the control panel, add the same rule there: TCP 445 from your client addresses only.
Step 7: Test and connect
Test on the server first, which rules out network problems:
smbclient //localhost/share -U aliceAfter entering the password you get an smb: \> prompt. Type ls to list the share and exit to leave. Then connect from a client:
- Windows: open File Explorer, type
\\198.51.100.10\sharein the address bar and log in asalice. - macOS: in Finder choose Go → Connect to Server and enter
smb://198.51.100.10/share. - Linux: install
cifs-utilsand mount the share:sudo mkdir -p /mnt/share sudo mount -t cifs //198.51.100.10/share /mnt/share -o username=alice,uid=$(id -u),gid=$(id -g)
Create a file from the client and confirm on the server that it landed on the volume with the right group:
sudo ls -l /srv/samba/shareMaintenance
Growing the volume
Enlarge the volume in your hosting control panel first. Because the file system sits directly on the device without a partition table, one command then extends it to the new size while it stays mounted:
sudo resize2fs /dev/vdb
df -h /srv/sambaSome platforms only show the new size after the volume is re-attached or the server is rebooted; check with lsblk before resizing.
Removing a user
sudo smbpasswd -x alice
sudo userdel aliceSeeing who is connected
sudo smbstatusTroubleshooting
NT_STATUS_LOGON_FAILURE. The user is missing from Samba's database or the password is wrong. Runsudo pdbedit -L, thensudo smbpasswd -a aliceagain.NT_STATUS_ACCESS_DENIEDwhen writing. Linux permissions block the user. Check that the account is insmbshare(id alice) and that/srv/samba/sharehas mode2770and groupsmbshare.- The share is empty after a reboot. The volume is not mounted and you are looking at the empty mount point on the system disk. Run
findmnt /srv/sambaand correct thefstabline. - Connection times out from a client but works on the server. A firewall blocks TCP 445 — yours, the provider's, or the client's internet provider.
- Anything else. Samba's logs are in
/var/log/samba/.
Frequently asked questions
Can I limit how much space each user may use?
The size of the volume is the limit for the share as a whole, which is one of the advantages of a separate volume: a full share can never fill the system disk. Per-user limits are a job for file system quotas on the volume rather than for Samba; Samba reports the quota to clients once the file system enforces it.
Do I need the nmbd service?
Not for a share you reach by IP address or DNS name. nmbd only provides NetBIOS name resolution and browsing for old clients on a local network. On an internet-facing server you can switch it off with sudo systemctl disable --now nmbd.
Is the traffic encrypted?
SMB 3 supports encryption, and you can make it mandatory by adding server smb encrypt = required to the [global] section of smb.conf; clients that cannot encrypt are then refused. Even so, a VPN between clients and server remains the safer design for access across the internet.
Should I partition the volume before formatting it?
You can, but for a volume that holds a single file system it brings no benefit and makes growing it a two-step job (resize the partition, then the file system). A file system directly on the device is simpler.