SMB with Samba
đ 2025-10-03
As mentioned earlier, my original goal was to set up a file server within my local Wi-Fi network. After researching various solutions and libraries, I decided to use the Samba library, an open-source tool for implementing the SMB protocol on Linux. Initially, I explored SFTP, as it is widely regarded as one of the most secure options for file sharing. However, I ultimately didnât feel the need to use SFTP because I didnât want to make my system public; it was intended to be accessible only within my local network. Another factor in my decision was that SFTP requires a separate client, while SMB, on the other hand, seemed easier to set up and offered better performance. It doesnât require any client software and is seamlessly integrated into Linux, Windows, and macOS. The final reason I chose SMB was that since version 3, SMB supports encryption in transit, adding a layer of security that aligned with my needs.
Installing Samba in a Linux environment is straightforward:
sudo apt update && sudo apt install samba. To configure the Samba service, you'll first need to stop the Samba Daemon process: sudo systemctl smbd stop. The smbd process is the central component responsible for file sharing, authentication, and authorization (including user management). It also listens for requests from clients (such as Linux, Windows, and macOS machines). Once you start Samba, the smbd process runs in the background. When a client attempts to access a shared folder on the server, it sends an SMB request. smbd processes the request, performs the necessary checks, and serves the requested data or resource.
To configure Samba, you need to modify the configuration file located at /etc/samba/smb.conf. It's a good practice to create a backup of your smb.conf configuration file before modifying it. You can do this by running the following command: sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak While there are some default settings already included, I chose to use my own custom configuration, which looks something like this:
# Global Settings
[global]
server string =
interfaces = lo eth0 192.168.64.0/24
bind interfaces only = yes
client min protocol = SMB3
client max protocol = SMB3
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
log level = 3
log file = /var/log/samba/%I%t.log
# Shared folders
[shared_folder_1]
path = /path/to/your/volume
force user =
force group =
force create mode = 0664
force directory mode = 0775
guest ok = no
public = no
writable = yes
valid users = @smbgroup
hosts allow = 192.168.64.0/24
strict locking = yes
In the global settings section of the configuration file, we define general parameters for the Samba server:
client min protocol and client max protocol: These settings enforce the minimum and maximum SMB protocol versions that can be used by clients when connecting to the server. In this case, both are set to SMB3, ensuring that only SMBv3 connections are accepted, which is more secure than older versions like SMBv1.In the shared folder settings section, we define the properties of each shared resource:
force user and force group: Ensures that all files within the shared folder are created and owned by a specific user and group. These can be left empty or set to a specific user/group as needed.For more configuration options, you can refer to the manual page for smb.conf here.
For security and best practices, it's a good idea to create a separate user and user group for SMB access. So, I created the following:
sudo groupadd --system smbgroup
sudo useradd --system --no-create-home --group smbgroup -s /bin/false smbuser
--system: This flag indicates that youâre creating a system user rather than a regular user. A system user is typically used for running services or system processes and generally doesn't have login capabilities or a home directory. System users often have lower user IDs (UIDs) to distinguish them from regular users.
--no-create-home: This option tells the system not to create a home directory for the user. Normally, when you create a user, a home directory is created in /home/username. Since this is a system user for Samba, we donât need a home directory.
--group smbgroup: This flag assigns the new user (smbuser) to the existing group named smbgroup. If the group smbgroup doesnât already exist, it will be created.
-s /bin/false: This specifies the userâs login shell. By setting the shell to /bin/false, the user will not be able to log in interactively via the terminal. It essentially disables shell access, which is a common practice for system users that donât need to log in to the system, like a Samba user.
In addition to creating the Linux user and group, the user also needs to be added to Samba:
sudo smbpasswd -a smbuser
Here are some useful commands to modify the password or delete a Samba user (not a Linux user) later:
# Modify password
sudo smbpasswd smbuser
# Delete Sambe user
sudo smbpasswd -x smbuser
I also access the files shared via SMB using a containerized FileBrowser. The directories need to be readable and writable by the user running inside that container. Since I prefered not to use the smbuser account there, I configured the force user and force group properties in Samba to ensure that files are read and written under that specific user's name running the FileBrowser container.
Now that everything is setâSamba is configured, the Linux user and group are created, and the user has been added to SambaâI just had to reload the service with the following command: sudo service smbd restart
To verify that everything is working correctly I checked the status of the Samba service using systemctl: sudo systemctl status smbd
To test the SMB connection, I tried to connect through a client. In my case, on macOS, I used Finder â Go â Connect to Server... using this URL format: smb://<your ip>/<shared folder name from config>.
Noice! đ