//------------------------------------------------------------------- //-------------------------------------------------------------------
setting up a Samba file server on VPS

Install Samba File Sharing Server on Linux 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:

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

On AlmaLinux, Rocky Linux, and RHEL:

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

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

smbd --version

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

For UFW on Ubuntu and Debian, you can run:

sudo ufw allow samba
sudo ufw reload

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

sudo firewall-cmd --permanent --add-service=samba
sudo 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:

sudo mkdir -p /srv/samba/share

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

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:

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:

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:

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

Edit the Samba configuration file with your desired text editor:

sudo nano /etc/samba/smb.conf

Add this configuration at the end of the file:

[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:

sudo groupadd sambausers

Create a system user for Samba with the commands below:

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

Set directory ownership with the following command:

sudo chgrp sambausers /srv/samba/share

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

sudo smbpasswd -a sambauser

Enable the user with:

sudo smbpasswd -e sambauser

Now, validate your configuration with the following command:

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:

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

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

sudo systemctl enable --now smb nmb
sudo 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:

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

Mount the share with the following commands:

sudo mkdir /mnt/vpsshare
sudo 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:

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:

[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:

sudo systemctl restart smbd nmbd

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

FAQs

Why can I not connect to my Samba share from Windows?

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.

How do I change a Samba user password?

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

Can I limit access Samba share to specific IP addresses?

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

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

Post Your Comment

PerLod delivers high-performance hosting with real-time support and unmatched reliability.

Contact us

Payment methods

payment gateway
Perlod Logo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.