Install Samba File Sharing Server on Linux VPS

Updated on Apr 18, 2026
Mila H
5 MINS READ
Table of Contents
setting up a Samba file server on VPS

If you need a reliable way to share files between Linux and Windows clients, setting up a Samba file server on VPS is a simple method using the SMB/CIFS protocol. Samba transforms your Linux server into a network file server that works with Windows, macOS, and other Linux systems, which makes it ideal for centralized storage solutions.

In this guide, you will learn to build a lightweight Samba file server on a High Storage VPS, configure a secure share, and verify access from typical clients.

Prerequisites to Build a Samba File Server on VPS

Before setting up your Samba file server on VPS, ensure you have the necessary environment ready with a reliable hosting provider like PerLod Hosting.

  • A High Storage VPS with root or sudo access.
  • Basic command-line knowledge.
  • Network access for client connections.

Once you are done, proceed to the following steps to install and configure the Samba file server on the Linux VPS.

1. Install Samba on Linux VPS

The Samba package is available in the default Linux repositories. To install the Samba file server, run the system update and use the commands below based on your Linux distro to install it.

On Ubuntu and Debian-based distros:

Bash
sudo apt update && sudo apt upgrade -ysudo apt install samba samba-common-bin -y

On AlmaLinux, Rocky Linux, and RHEL:

Bash
sudo dnf update -ysudo dnf install samba samba-common samba-client -y

Once your installation is completed, verify the Samba installation by checking its version:

Bash
smbd --version

After the Samba installation, you must allow its traffic through the firewall.

For UFW on Ubuntu and Debian, you can run:

Bash
sudo ufw allow sambasudo ufw reload

For Firewalld on AlmaLinux and Rocky Linux, you can run:

Bash
sudo firewall-cmd --permanent --add-service=sambasudo firewall-cmd --reload

Also, you must create a directory for your Samba file server on VPS. To do this, you can run the command below:

Bash
sudo mkdir -p /srv/samba/share

Then, set the correct permissions for the Samba share directory with the following command:

Bash
sudo chmod 2775 /srv/samba/share

For Samba shares on AlmaLinux and Rocky Linux only, you must set the correct SELinux context. To do this, run the commands below:

Bash
sudo semanage fcontext -a -t samba_share_t "/srv/samba/share(/.*)?"sudo restorecon -Rv /srv/samba/share

Note: If semanage is not found, install it with the commands below:

Bash
sudo dnf install policycoreutils-python-utils -y

2. Configure Samba File Share on Linux VPS

At this point, you must configure the Samba daemon to define how resources are shared across the network. The main configuration file, located at /etc/samba/smb.conf, controls security settings, workgroups, and share definitions for your Samba file server on VPS.

In this step, you can back up the original config and add a custom share block to enable client access.

Back up the original configuration file with the command below:

Bash
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup

Edit the Samba configuration file with your desired text editor:

Bash
sudo nano /etc/samba/smb.conf

Add this configuration at the end of the file:

Bash
[share]   comment = Storage VPS File Share   path = /srv/samba/share   browsable = yes   writable = yes   guest ok = no   valid users = @sambausers   create mask = 0664   directory mask = 0775   force group = sambausers

Save and close the file.

Create a dedicated group for Samba with the command below:

Bash
sudo groupadd sambausers

Create a system user for Samba with the commands below:

Bash
sudo useradd -M -s /sbin/nologin sambausersudo usermod -aG sambausers sambauser

Set directory ownership with the following command:

Bash
sudo chgrp sambausers /srv/samba/share

Samba maintains a separate user database. You must add your user and enter a password when prompted:

Bash
sudo smbpasswd -a sambauser

Enable the user with:

Bash
sudo smbpasswd -e sambauser

Now, validate your configuration with the following command:

Bash
testparm

This tool validates /etc/samba/smb.conf and displays the active configuration. Fix any errors before proceeding.

3. Start and Enable Samba Services

At this point, you can start Samba services and enable them at boot. The smbd daemon handles file sharing, and nmbd provides NetBIOS name services.

On Ubuntu and Debian, you can use the commands below:

Bash
sudo systemctl enable --now smbd nmbdsudo systemctl status smbd nmbd

On AlmaLinux and Rocky Linux, you can run the following commands:

Bash
sudo systemctl enable --now smb nmbsudo systemctl status smb nmb

4. Access Samba Share

Now that the service is active and the firewall is configured, your Samba file server on VPS is ready to accept connections. In this step, you can connect to the shared directory from a client machine to verify that permissions are working correctly on your High Storage VPS.

From Windows:

  • Open File Explorer.
  • In the address bar, enter: \your-vps-ip\share
  • Enter username: sambauser and the password you set.
  • To map as a network drive, right-click the share and select "Map network drive".

From Linux:

List available shares with the command below:

Bash
smbclient -L //your-vps-ip/ -U sambauser

Mount the share with the following commands:

Bash
sudo mkdir /mnt/vpssharesudo mount -t cifs //your-vps-ip/share /mnt/vpsshare -o username=sambauser

To verify functionality, you can create a test file from your client machine to verify read and write access.

Check active connections on the server with the command below:

Bash
sudo smbstatus

This displays current connections, locked files, and share usage.

Security Recommendations for Samba Share

For more security, you can add the following settings to the global section in the /etc/samba/smb.conf file:

Bash
[global]   map to guest = never   server min protocol = SMB3   log file = /var/log/samba/log.%m   max log size = 1000   hosts allow = your-allowed-network/24 127.0.0.1
  • map to guest = never disables guest access.
  • server min protocol = SMB3 enforces modern encryption protocols.
  • hosts allow restricts access to specific networks.

Restart Samba after any configuration changes:

Bash
sudo systemctl restart smbd nmbd

Your Samba file server on VPS is now operational and ready for production use on your High Storage VPS.

Conclusion

At this point, you have built a secure Samba file server on VPS for file sharing between Linux and Windows. This setup gives you full control over your private data without third-party limits. For the best performance and scalability, we recommend deploying on a High Storage VPS.

We hope you enjoy it. Subscribe to our X and Facebook channels to get the latest updates and articles.

For further reading:

Implement an Automated Restic backup to Storage VPS

AlmaLinux vs Rocky Linux vs CentOS Stream

Set up LEMP Stack on VPS

Samba Connection issues are usually caused by firewalls blocking ports 139 and 445. Check the firewall rules on your VPS and ensure your hosting provider allows this traffic.

Samba uses a separate password database from your system users. To update a password, just run sudo smbpasswd user_name.

Yes, you can restrict access by adding the hosts allow directive to your /etc/samba/smb.conf file.