Dynamic Private share for your users


Recommended Posts

First of all im new to unraid, coming from a qnap nas, one of the feature that i found out unraid didnt support was "Home" shares. What that feature is, a share called "homes" and every user gets there own subfolder in that share that only they can access. seeing that all my users use this as a remote storage for Docs, Pics, etc. and just mapped the folder to windows to use. this is one feature i could not go with out. so Ive made some "tweaks" to unraid to be able to have this feature and wanted to share my findings for anyone looking for something like this. need less to say, im not responsible for any data loss thats up to you to take the risk.

 

1) Create a share called "homes" (NOTE: with a 's')and set the export to "no" security to "Public and leave everything else to default

homes.thumb.png.9f0d2e6be013a3c692c31f0ecfc9fbbd.png

 

2) create a directory under "/mnt/user/appdata" called "home" (NOTE: without the 's')

 

3) goto the directory created in the last step ("/mnt/user/appdata/home") and create a file called "create_userdir.sh" and set permissions to 777 (there maybe a more secure way to allow this script to run but this worked for me).

 

4) open the file created in the last step ("create_userdir.sh") with a editor then copy, paste, save the code below

#!/bin/sh

USER=""

 if [ $# -gt 0 ]; then
	USER=$1
 fi
 
 if [ $USER ]; then
	if getent passwd | grep -q "^$USER"":"; then
		if [ ! -d "/mnt/user/homes/$USER" ]; then
			mkdir -m 777 "/mnt/user/homes/$USER"
			chown $USER:100 "/mnt/user/homes/$USER"
			exit 0
		else
			exit 0
		fi
	else
		exit 1	
	fi
 else
	exit 1
 fi

5) Mount your usb boot drive and open "/config/smb-extra.conf" then copy,paste,save the code below (make sure you paste the code AFTER anything thats already in that file. DO NOT delete/overwrite anything there)

#Home_Start
[home]
comment = Home
path = /mnt/user/homes/%U
browsable = yes
invalid users = guest
writable = yes
read list = "%U"
write list = "%U"
valid users = "%U"
root preexec = /mnt/user/appdata/home/create_userdir.sh '%U'
#Home_Stop

5b) when you done it should look something like this

smbextra.png.32b40806dae6fa2cb74df8de89e6d0cf.png

 

6)reboot & profit you will see a new share called "home"

 

Ok here the break down of what this do....

smb-extra.conf creates a dynamic share called "home"

when a user trys to access the share "home" a script called 'create_userdir.sh' is ran

what "create_userdir" do is, take the username that is trying to access this and check if there "private" directory already exist and if not create the directory (this is for when a new user is create and dont already have a "private" directory, its to make sure that the share "home" have a valid directory to be mounted to)

smb-extra.conf then dynamically sets the path to what ever the current user "private" directory is.

 

because of how the shares works per user. your only able to see YOUR "private" share.

 

If an admin wants to make changes or delete some files thats not theirs they can go to "/mnt/user/homes/" to see all the users "private" directory.

 

Hope this helps someone, and feel free to leave a reply if you need some help.

 

 

Edited by Alacard
Link to comment
  • 2 years later...
  • 1 year later...

Sorry to necro this semi-old thread - but I am also looking for and missing this feature.

It would be great if this script or another could be implemented as a Plugin! So people can choose whether to have it or not and if enough people download it maybe it could be a built in option.
 

@Alacard - are you still using this? If so, what version are you using? Thanks!

Link to comment
  • 4 months later...
  • 2 weeks later...
  • 1 month later...
  • 3 months later...

I just started with Unraid 6.12.6 and generated users and for each user a share with the name of the share identical to the <username> of each user.

 

Additionally I generated a share called "homes" (with s).

 

Then i connected on my Windows machine to \\<SERVERIP>\homes and i was surprisingly connected with my own <username> share. This looked on the beginning very strange to me but is possibly the "inbuilt" solution which the users in this thread were looking for. I am sure that I was connected with my own "username" share because there was already data stored while the share "homes" which I manually generated was still empty.

 

So I made the share "homes" invisible for SMB again and was still able to connect from my Windows machine to \\<SERVERIP>\homes  but again I was connected with my own share <username>.

 

to summarize:

1.) generate for every username one usershare and use exactly the same name for share and username

2.) each user connects via SMB to \\SERVERNAME\homes and each user will be connected to it's own share

that's it.

 

Unfortunately this feature (or bug?) seems not to be  found in the official UNRAID documentation. I searched for "homes" and found nothing explainting this observed behaviour

Edited by frimu
Link to comment

Never heard of this behaviour before!   I think a bit more digging into why you get it needs doing, although I am not sure what the next steps are at the moment.

 

Maybe if you attach your system’s diagnostics zip file to your next post in this thread it might give a clue.  it is always a good idea when asking questions to supply your diagnostics so we can see details of your system, how you have things configured, and the current syslog.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.