As part of the installation step of some software on a Ubuntu VM I'd like to create a samba share. How would I go about doing that from the command line?
You can edit /etc/samba/smb.conf and enter the share name, location, and who should access it. There are several examples in the file itself.
Here's online guide for entering new shares in the smb.conf file:
Use Samba's net usershare command to share directories from the command line, IMHO this is less clunky and much safer than fiddling around in the main smb.conf file:
To make these shares permanent (i.e. persist over reboots) create a file for each share under /var/lib/samba/usershares/ like this:
This has a further advantage that if you're using a desktop like KDE or GNOME/MATE/Unity the directories will show up as shared in the file manager (Dolphin, Nautilus etc.). That's cause the net username//var/lib/samba/usershares/ thing is the same mechanism that Dolphin and Nautilus use when you share directories in the GUI.