Samba Restrict File Sharing To Particular Users or Network Addresses

by Vivek Gite · 5 comments

All my local Linux user accounts will be able to log in to my Samba server and access share. How do I restrict access to particular users or network subnet such as 192.168.2.1/24?

You can use TCP wrappers to limit subnet access via:

  1. /etc/hosts.allow - This file describes the names of the hosts which are allowed to use the local INET services, as decided by the /usr/sbin/tcpd server.
  2. /etc/hosts.deny - This file describes the names of the hosts which are NOT allowed to use the local INET services, as decided by the /usr/sbin/tcpd server.

For example, allow access to smbd service inside LAN only via /etc/hosts.allow:

smbd : 192.168.2.

However, samba may or may not be built to support tcp wrappers.

hosts allow: Samba Configuration

Open your smb.conf file and add the following line to [share]

[share]
  hosts allow = 192.168.2. 127.0.0.1

valid users: Samba Configuration

Open your smb.conf file and add the following line to [share]

[share]
  valid users = user1 user2 @group1 @group2

read only & write only: Samba Configuration

You can also set read and write access to set of users with the read list and write list directives.

[share]
     read only = yes
     write list = user1 user2 @group1 @group2

Examples

Make [sales] share read only but allow user tom and jerry to write it:

[sales]
     comment = All Printers
     path = /nas/fs/sales
     read only = yes
     write list = tom jerry

You can also configure iptables to allow access to the Samba server.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 5 comments… read them below or add one }

1 Suvankar 10.16.09 at 10:26 am

Hello! Sir,
I have one question. That is “how can I share a specific file or folder in between three or four ubuntu based computer.
plz. help..
Thank you.

2 Vivek Gite 10.16.09 at 10:50 am

Use nfs server and client to share files between Linux / UNIX computers.

3 Sebastian 10.16.09 at 11:24 am

Hi!
I do that using acl´s, is that wrong? or not engouraged??

4 Vivek Gite 10.16.09 at 11:39 am

ACL are set on files and directory and not on share names. You can use ACL for controlling and tuning file level access.

HTH

5 ipv6 learning 11.11.09 at 2:48 pm

off-topic: how connect to shared folder using IPv6 without DNS Server, I mean connect using the IP.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All