26

Exact same question as Create a user for sharing purposes only but using CLI instead of GUI.

I'd like to allow login access to a shared SMB directory, but the users get no other access to the server.

4
  • The question you refer to deals with guest access to samba, in other words everyone on the network has access to the share with no password. In your case, if that's what you want, what's the point of creating a special "user for samba only", if all have access anyway? Oct 14, 2014 at 15:04
  • As the other asker also said, I do want logins and passwords for the file share.
    – Foo Bar
    Oct 14, 2014 at 15:05
  • Not sure what other asker you are talking about. See my answer below, hope it helps. Oct 14, 2014 at 15:19
  • Thanks. I was referring to: askubuntu.com/questions/152020/…
    – Foo Bar
    Oct 14, 2014 at 16:47

2 Answers 2

57
  1. Create a user on the server:

sudo adduser --no-create-home --disabled-password --disabled-login sambausername

  1. Add that user to samba (you'll be asked to type a password):

sudo smbpasswd -a sambausername

  1. Create a share by editing /etc/samba/smb.conf. For example, you can add something like this to the bottom:

    [share name]
        comment = whatever
        path = /path to share
        browsable = yes
        read only = no
        guest ok = no
    
  2. Now is a good idea to restart samba:

sudo service smbd force-reload

  1. Go to the client machine and try to access the share with the username and password you've just set up.
5
  • 9
    --no-create-home --disabled-password --disabled-login This saved my day! Still helpful in 2017!
    – Stan
    Dec 5, 2017 at 11:39
  • 2
    @Stan Thanks for the feedback, glad it was helpful. Dec 5, 2017 at 15:40
  • How do i use this user as a "valid users = <username>". For some reason this does not work? If i use the username of a user with a dashboard it will work. Otherwise it doesn't.
    – Myron
    Oct 4, 2018 at 9:44
  • how can I do first step on centos?
    – Sollosa
    Mar 11, 2019 at 11:03
  • maybe better: sudo adduser --no-create-home --disabled-password --disabled-login --gecos "" sambausername (where --gecos "" option to skip the chfn interactive part askubuntu.com/a/94067/828892 and uid < 1000 for hidden account askubuntu.com/a/22010/828892)
    – acgbox
    Nov 12, 2019 at 21:10
8

With Active Directory (Samba 4.0+)

If you have Samba 4.x and it is connected to an Active Directory, you can use samba-tool to add a user to it:

samba-tool user add USERNAME-HERE

Please see Samba AD DC howto for more info

Answer Extracted from Cyberciti

To verify your Samba Version just user the command

samba -V

Example Output:

Version 4.3.11-Ubuntu
7
  • Should this be the new accepted answer?
    – Pichan
    Feb 22, 2017 at 12:59
  • 3
    Scratch that. Didn't work after all :/ Seems that samba-tool is for Active Directory.
    – Pichan
    Feb 22, 2017 at 13:02
  • 4
    A Futher search shows that you need to config a Samba AD to use this feature. Feb 22, 2017 at 13:18
  • 1
    Maybe the AD requirement should be more prominent?
    – Joril
    Feb 28, 2018 at 10:05
  • 3
    samba-tool is for Active Directory (AC) provisioning only askubuntu.com/a/490342/828892
    – acgbox
    Nov 11, 2019 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .