Samba Restrict File Sharing To Particular Users or Network Addresses

If you are running Samba on a Linux server and want to restrict file sharing to particular users or network addresses, you can use Samba’s built-in access control mechanisms. Here are the steps to do so:

  1. Open the Samba configuration file for editing:
sudo nano /etc/samba/smb.conf
  1. Scroll down to the [global] section and add the following lines:
security = user
valid users = user1 user2

These lines set the security mode to user and allow only user1 and user2 to access the shared files.

  1. Scroll down to the [homes] section and add the following lines:
valid users = %S

This line allows only the user whose home directory is being shared to access the files.

  1. To restrict access by network address, you can use the hosts allow and hosts deny parameters. For example, to allow access only from the 192.168.1.0/24 subnet, add the following line:
hosts allow = 192.168.1.
  1. Save and exit the file.
  2. Restart the Samba service to apply the changes:
sudo systemctl restart smb

These steps allow you to restrict file sharing to particular users or network addresses in Samba. By default, Samba uses the file system permissions to control access to shared files, so you may also need to set appropriate file permissions for the files and directories being shared.

Leave a Comment