In Windows it's easy to get file sharing to work. At least I can make it work all the time. Part of it is the graphical interface, but file sharing in Linux, in my case Ubuntu has it's peculiarities. Even if you use the Ubuntu GUI tools, it doesn't always work. It has cost me countless hours over the years and every time I have to reconfigure Samba I'm in hell. So this is my guide on how to enable Samba sharing in Ubuntu.
In this example we have the server user joediapna
, two actual people diana
and joep
and a shared (somewhat public) computer account in the living room discobal
.
List the folders or volumes you want to share. I want to share two volumes, or to be more precise a single folder in each volume. The Workspace
volume is where for example software installers are shared and it has private folders for the "real" users. The second volume Data
is used to share data between all computers. I want the server to be the owner of all volumes/data, except the private folders.
One more thing: the sharename cannot have the same name as the folder it represents! It is however case-sensitive so Data
is not the same as data
.
Folder / volume | Sharename | Owner |
---|---|---|
/mnt/Data/data | Data | joediapna |
/mnt/Workspace/workspace | Workspace | joediapna |
/mnt/Workspace/Diana | - | diana |
/mnt/Workspace/Joep | - | joep |
joediapna
can read and write anywhere (except the private folders). The sambashare
group can only read anywhere (except the private folders). We need the x
to build the tree of subfolders.Group | Sharename | Owner |
---|---|---|
/mnt/Data/data | Permissions | Permissions |
joediapna | rwx / 7 | rwx / 7 |
sambashare | r-x / 5 | r-x / 5 |
other users | r-x / 5 | r-x / 5 |
User | Type | Group |
---|---|---|
diana | Admin | joediapna , sambashare |
diana | Admin | joediapna , sambashare |
discobal | User | sambashare |
joediapna | Owner | joediapna , sambashare |
joep | Admin | joediapna , sambashare |
Mount the volumes you want to share. To mount volumes at least you should make the mount points (folders) and mount the volume. I have ZFS volumes which should mount automatically after every reboot. I haven't tested that yet. If you are mounting other folders, you have to add them to /etc/fstab
. Please Google for that.
sudo mkdir /mnt/Datasudo mount Data /mnt/Datasudo mkdir /mnt/Workspacesudo mount Workspace /mnt/Workspace
Check with ls -l
for current owner and permissions.
cd /mnt/Datals -l
Data
: The owner should be joediapna:joediapna
and the permissions should be drwxrwxr-x
(775
). With these permissions the owner (the user joediapna
) can do everything, the group joediapna
can read and write. All other users can only read. We are going to apply these permissions on all the files and folders.
sudo chown -R joediapna:joediapna /mnt/Data/datasudo chmod -R 775 /mnt/Data/data
Workspace
: The owner should again be joediapna:joediapna
and the permissions should also be drwxrwxr-x
(775
). We are not going to apply these permissions on all the files and folders.
cd /mnt/Workspacels -lsudo chown joediapna:joediapna /mnt/Workspace/workspacesudo chmod 775 /mnt/Workspace/workspace
Now go in one level deeper and check for each folder what the permissions should be. Apply them for each folder recursively.
cd /mnt/Workspace/workspacels -lsudo chown -R joediapna:sambashare /mnt/Workspace/workspace/downloadsudo chmod -R 775 /mnt/Workspace/workspace/downloadsudo chown -R joep:joep /mnt/Workspace/workspace/joepsudo chmod -R 700 /mnt/Workspace/workspace/joep
Create groups. The joediapna
group already exist as it was made with the initial user during setup of Ubuntu. We only have to make the sambashare group.
sudo groupadd sambashare
Create users. We do have to create 3 users: diana
, discobal
and joep
. This is the example for the first.
sudo useradd -m diana -p PASSWORDsudo usermod -L dianasudo usermod -a -G joediapna dianasudo usermod -a -G sambashare diana
Install Samba:
sudo apt updatesudo apt install samba
Open the file Samba configuration file:
sudo nano /etc/samba/smb.conf
Change the workgroup to your Windows workgroup if you have one. I have called it BALZAAL
.
# Change this to the workgroup/NT-domain name your Samba server will part ofworkgroup = balzaal
Scroll all the way to the bottom and add the shares.
[Data]path = /mnt/Data/databrowseable = yeswriteable = yescreate mask = 0775directory mask = 0775guest ok = no[Workspace]path = /mnt/Workspace/workspacebrowseable = yeswriteable = yescreate mask = 0775directory mask = 0775guest ok = no
Save and close by pressing Ctrl-O
to save and Ctrl-X
to close. Now restart Samba.
sudo service smbd restart
Add a rule in the firewall to allow Samba traffic.
sudo ufw allow samba
The Samba user passwords aren't the same as the system users we just created. I always forget that. We have to add that password to Samba too. So for each user:
sudo smbpasswd -a diana
If everything went right, which it never does in my experience, you should now be able to browse these shares. From a Unix machine (Mac or Linux) type smb://xxx.xxx.xxx.xxx/Data
or from Windows: \\xxx.xxx.xxx.xxx\Data
.
If it doesn't work... First check if Samba is installed and running:
smbd --versionsystemctl status smbdsystemctl status nmbd
If yes, try to restart the Samba service:
sudo systemctl restart smbdsudo systemctl restart nmbd
Then install a small Samba GUI. It's a GUI, so you can only run it through VNC. See if you see anything strange there.
sudo apt install system-config-sambasudo system-config-sambasudo touch /etc/libuser.conf