I need help with Samba
configuration.
What I want to achieve is configuration, where windows user on share see only his files. This is simply achived With configuration like this:
Users are authorized by Windows AD Server
[BACKUP]
comment = BACKUP STORAGE LOCATION
path = /storage/BACKUP
read only = no
browseable = yes
writable = yes
create mode = 0600
directory mode = 0700
force directory mode = 0700
force create mode = 0600
access based share enum = yes
hide unreadable = yes
valid users = "@DOMAINNAME+SOMEUSERGROUP"
It works ok but...
On the server side, everything in directory /storage/BACKUP
keeps files of every user.
So I would like to create directory here for every user (I Can't use [home], because it's already used)
So i Would like to keep it like this:
/storage/BACKUP/username/
So when i change path, and add %U
at end, everything is almost ok.
The problem is that i need to manually create directory /storage/BACKUP/username
.
So what i need is somehow force Samba
to create this directory before user to access this share.
I've tried adding add user script = /path/to/mkdir /storage/BACKUP/%U
But this is not working because:
- I don't know why ;)
- I've already have users logged in before
- It should start for new created users, this will be ok for me, but it not works.
I'm not creating users in linux, after they login, so i'm not using add user/machine script anywhere else.
So i want to force Samba
to create directory for user, when this user tries to connect.
I'm searching google from couple of hours, and didn't find a way to do it that will work for me.
I need to keep /server/BACKUP location for everyone, but on the server side, Need to keep files in separated directories per user, so creating a new share is also not a solution.
You can use the
preexec
orroot preexec
options for this. They specify a script that is run upon connection to a share. In case ofpreexec
the share is run as the connecting user, and as root withroot preexec
.In your share:
where
/etc/samba/gendir.sh
looks somewhat like this:Depending on your requirements, add
chown
and/orchmod
statements to the script.In my case the situation is slightly different - I'm using Samba as my DC with FreeNAS. I'm not sure if this is due to the FreeBSD build or Samba as DC, but either way the username to the script in @Sven's answer above prepends the Domain Name so $1 ends up being DOMAINuser not user, and the directory requested by the home share is DOMAIN\user not just user.
I've adjusted the script like this, and it now works a charm:
In addition, the machines also try to create their own directories, with a trailing _ character. The username has a $ to designate computer account. I've modified the script like this to support computer directories:
I intend also to create profile directories the same way.
This is standalone server. In share auxilary parameter i have added:
All users have acccess to scratch and full control over all files, however every user has his own dir created automatically.
If you are using the PAM mechanism, you might want to add the following line to the file
/etc/pam.d/common-session: