0

In my samba config - I would like it to link "valid users" in the example share below to the example text file:

security = user

[example share]
path = /example/path/here
read only = no
guest ok = no
valid users = (LINK TO TEXT FILE)

Validusers.txt

user1, user2, user3
2
  • No, you cannot do that, you could use a group instead and make the required users members of that group. Jan 15 '21 at 13:09
  • @RowlandPenny it seems I have an answer that does allow me to do that
    – ekv_56
    Jan 20 '21 at 11:33
1

You can't do what you've asked, but there are three alternatives I'll describe here

  1. Include a syntactically valid smb.conf snippet that defines your users.

     valid users = user1, user2, user3
    

    Include this snippet in your share definition. For example, if the snippet is called /usr/local/etc/smb.valid_users.conf you would declare your share like this

     [example share]
     path = /example/path/here
     read only = no
     guest ok = no
     include = /usr/local/etc/smb.valid_users.conf
    

    When you change the list of users you may need to restart samba (systemctl restart smbd). Notice that because this is an include, any valid code can be added - including entire shares that give away far more access than you would expect. Do not allow untrusted users access to change the configuration file!

  2. Put the users into a group and reference the group in the share definition.

     valid users = @usersgroup
    

    Then exactly as usual you create the group usersgroup (see groupadd or addgroup depending on your OS variant) and add your users to it

  3. Template the smb.conf and substitute into it as necessary. (The least favourite of my options.) Copy smb.conf to smb.conf.template and use this line in your share definition,

     valid users = %USERSLIST%
    

    Then use something like sed to substitute into the template

     sed 's/%USERSLIST%/user1, user2, user3/g' /etc/samba/smb.conf.template >/etc/samba/smb.conf
    
1
  • 1
    Loving option 1 thanks very much @roaima
    – ekv_56
    Jan 20 '21 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.