Is there a possibility to temporarily share a directory per Samba?

With Python 3 i can serve the current directory per HTTP using:

python -m http.server.

I'd like to do the same thing with Samba.

  • Is the net share add command what you're looking for?
    – derobert
    Nov 13, 2012 at 17:14
  • Or possibly net usershare...
    – derobert
    Nov 13, 2012 at 17:15

4 Answers 4


This might come a little late, but the Impacket python project provides exactly what you were asking for.

Within the examples folder is an ad-hoc smbserver.py and many further helpful scripts. Citing their example, to SMB-share your /tmp directory becomes as easy as:

smbserver.py -comment 'My share' TMP /tmp"


There doesn't appear to be a way to create an ad-hoc share similar to the way exportfs does it for NFS on Linux and share does it on Solaris. Reasons may vary but you could technically do something like described in the page for Running Multiple Servers on the same machine and with the custom smb.conf accomplish what you need to do.

There is also an option to create and delete shares dynamically using SWAT, which will require changes to smb.conf to allow this to happen see sections on add share command and delete share command

Personally if you want to have a share dynamic you might want to share your home directory and use dynamic home shares via samba discussed in many places including Ubuntu forums, and Samba mailing list.


Depending on how old your samba daemon is, and the config options used when it was built, you may still have the option of defining a "dynamic" share in your smb.conf, pointed at say /var/dynamic/, see below, and then simply adding a symbolic link to the directories you temporarily want to share into the directory.

This hack require the wide links option to be set to yes, to allow samba to follow links outside of the shares root. Unfortunately a couple of years back the Samba crew tweaked their default config to prevent wide shares, as it could be exploited. Google for: Samba and "wide links" for the history and work arounds.

    comment = Somewhere to park dynamic shares 
    path = /var/dynamic
    read only = Yes
    inherit acls = Yes
    follow symlinks = yes
    wide links = yes

A quick test should see if your good e.g.

mkdir -p /var/dynamic/test
cd /var/dynamic
ln -s test a_link
ln -s /tmp/  tmp_test

Lets say you want to quickly share /somefolder to someuser temporary readonly.

Add a system user:

useradd -r someuser

Often by default the folder is other-readable (check with ls -ld /somefolder), if you need to force it:

chmod -R o+r /somefolder

Add the user to samba with some password like:

smbpasswd -a someuser

Quickly edit smb.conf and add at the bottom

path = /somefolder
read list = someuser

exit, save, and finally run

smbcontrol smbd reload-config

et voila.

Obviously you may want to remove the "someshare" section once done and rerun the reload-config command.

Disclaimer: i didnt fully test this but i was amazed how simple the answer to the question could be. You can possibly skip some steps and dive straight into editing of smb.conf if you already have some user with existing samba access - exactly what i just ran into.

You must log in to answer this question.

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