Sharing Folders On External Usb Hdd For Total Beginners On Freshly Installed Mint 20.2 Cinnamon And Mate

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
JezekiljMonk
Level 3
Level 3
Posts: 105
Joined: Mon Dec 30, 2019 7:33 am
Contact:

Sharing Folders On External Usb Hdd For Total Beginners On Freshly Installed Mint 20.2 Cinnamon And Mate

Post by JezekiljMonk »

For application of this tutorial on LMDE5 see what little is different in this post
viewtopic.php?p=2159680#p2159680
GOALS OF THIS TUTORIAL Starting from the freshly installed machines with: Linux Mint 20.2 Cinnamon and with MATE (in this example those are also Virtual Machines on VirtualBox) I want to demonstrate many issues related to Folder Sharing from and External USB HDD

In all the examples the User Account Name is: testuser

PC Names shall be: Mint-20C for Cinnamon and Mint-20M for Mint with MATE Desktop

You can check your PC Name by typing in Terminal (Ctrl + Alt + T)

Code: Select all

hostnamectl
It will look like this in our cases

Cinnamon

Code: Select all

testuser@Mint-20C:~$ hostnamectl
   Static hostname: Mint-20C
         Icon name: computer-vm
           Chassis: vm
        Machine ID: dafd9a61376b4676aa8b190bc1ed4b43
           Boot ID: 1eb3e6417c884252aad8200f555dd8e7
    Virtualization: oracle
  Operating System: Linux Mint 20.2
            Kernel: Linux 5.4.0-77-generic
      Architecture: x86-64
MATE

Code: Select all

testuser@Mint-20M:~$ hostnamectl
   Static hostname: Mint-20M
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 7a0781c5129d4f848f901e53f906eaf1
           Boot ID: de77013437c845bc946a64aace893a80
    Virtualization: oracle
  Operating System: Linux Mint 20.2
            Kernel: Linux 5.4.0-77-generic
      Architecture: x86-64
If you would like to change your PC Name type in Terminal

Code: Select all

hostnamectl set-hostname <New-Name>
Omit signs <,> when you type this name. Change shall be effective only after you reboot your PC

Concrete TASKS
1. Install necessary software
2. Set properly all kinds of permissions regarding samba and samba users. Set one Group of Users with name homeusers in our example we shall use john and mary
3. Explain how to properly mount HDD with respect to the Folder Sharing Goals
4. Set sharing of Folders (all on External USB HDD): Folder A, Folder B and Folder C so that
a) Folder A can only be accessed by testuser with all read-write-execute permissions applicable
b) Folder B can be accessed by testuser and by users from Group homeusers, all read-write-execute permissions applicable
c) Folder C can be accessed by testuser with all permissions and also by a Guest/Anonymous User but only with read and execute permissions, i.e. no possibility to write/delete.
5. Demonstrate proper access to these shared folders from various OSs, both through PCs Network IP Address and through its Symbolic PC Name where possible. Also explain how to improve visibility of Network Shared Folders between other Debian based PCs and with Win10 on a home Network.

As much as possible I will use GUIs, but still there is work to be done through Terminal as well. As for text editor I will use xed as it is default editor in both Mint Cinnamon and Mint MATE. In order to more easily follow this tutorial please first time you open something with xed go to Edit>Preferences>Editing and check 'Display line numbers'

So you should adjust in your own case testuser, homeusers, john, mary, hostnames, ip addresses, Folder Names as per your own case

I strongly recommend, if possible, to first experiment on a Virtual Machine and/or to create Timeshift image before you start. If your home Internet Server does not provide always same IP address for an individual PC (usually DHCP based on a MAC address of a PC), than symbolic names should be the only available option for accessing Shared Folders. Still it is way better to have DHCP server assigning always same local IP addresses based on MACs since Win7 won't be able in many cases to access shared folder through PC hostname.

For the purposes of this tutorial I am using Virtual Machines, but with Bridged Network Adapters, so the VMs are on the same Ethernet Network as all the other PCs and Android Devices and this doesn't in any way limit applicability of this tutorial. IP address set for this tutorial are 10.1.3.62 for Mint Cinnamon and 10.1.3.64 for Mint Mate.

My motivation for writing these tutorials is that when 20 months ago I switched from Win7 to Linux Mint 19.2 I needed immediately to learn about Folder Sharing. There were many available tutorials, almost exclusively covering the easiest cases of Folders being on PCs System Disk, especially on one's home folders, but there was none that actually explained how do you share something that is on another hard drive, especially if that is external USB HDD. So I am offering here the result of my 20-months long search into Network Folder Sharing. Hope this helps someone, especially the Linux newbies, since it is way more complex than usually presented.
EXPLANATION FOR LINUX MINT 20.2 WITH CINNAMON AND WITH MATE DESKTOP I shall now proceed with explanation with examples illustrated on Linux Mint 20.2 Cinnamon and MATE machines freshly installed for the purposes of this tutorial.
CHAPTER 1 Installation of additional applications for samba functionality and Network shares diagnosing a) for Cinnamon Desktop

We will first install samba. We also need cifs-utils (pre-installed on both Desktops), nemo-share (on Cinnamon, also pre-installed) and caja-share (On Mate, it is not pre-installed)

Open Terminal (easiest way by pressing together Alt + Ctrl + T) and type

Code: Select all

sudo apt install samba
Press 'y' when asked and wait for everything to be installed

b) For MATE

Open Terminal and type

Code: Select all

sudo apt install samba caja-share
In order to see 'Sharing Options' in File Manager by right-mouse click on a Folder icon, you will need to log-out than log-in.

This should be everything we need for this tutorial
CHAPTER 2 INITIAL SAMBA SETTINGS AND SAMBA USERS Much of this chapter and the tutorial as well is based on the following article
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-samba-share-for-a-small-organization-on-ubuntu-16-04

Still, we will adjust it as to cover our tasks set for this tutorial. Also, we will not use already existing group sambashares, but rather create our own group homeusers

2.1 BackUp of Samba Configuration File
It is always recommended to save a backup of initial samba configuration file, just in case, and verify that it has been done. So type in terminal (Both Cinnamon and MATE)

Code: Select all

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.initial
ls -l /etc/samba/
It should look like this

Code: Select all

testuser@Mint-20M:~$ ls -l /etc/samba/
total 32
-rw-r--r-- 1 root root    8 Apr 14 13:02 gdbcommands
-rw-r--r-- 1 root root 8942 Jul 20 11:28 smb.conf
-rw-r--r-- 1 root root 8942 Jul 20 12:42 smb.conf.initial
drwxr-xr-x 2 root root 4096 Apr 14 13:02 tls
Although the above mentioned tutorial mentions now to check existing network interfaces' names I did not find it relevant so I will skip it. Still if you like to change default eth0 Ethernet interface to the real interface name, like enp0s8, feel free to do it. In both cases this tutorial works. In case you don't know the names of your network interfaces type in Terminal

Code: Select all

ip link show
2.2 Modifications of Samba Configuration File

From now on unless specified differently everything will apply to both Cinnamon and Mate Desktops.

Let us now open samba configuration file in the default editor. Like mentioned earlier you may now want to activate Display of Line numbers.

Type in Terminal

Code: Select all

sudo xed /etc/samba/smb.conf
Now a configuration file should open stretching over several pages. At the top there will be a red line stating that file has been opened with Elevated Privileges, meaning that what we modify we will be able to save. What is of real interest to us is in lines 183-190

If you have never read anything about Folder/File Permissions in Linux I would recommend following link

https://help.ubuntu.com/community/FilePermissions

File creation mask and Directory creation mask need to cover all of our tasks. Later on we will limit what is too much of a permission for a particular Folder share

First digit is of no interest to us.
Second digit (by default it is 7) refers to maximum read(4)+write(2)+execute(1)=7 permissions for the file owner. It will remain as it is 7.
Third digit (by default it is 0) refers to the users belonging to group to which this folder belongs. Since for Folder B we want to grant all the permissions to our group: homeusers, we will need here 7 as well. On another level we will then reduce this for folders A and C.
Fourth digit refers to Guest/Anonymous Users (by default it is 0). In our case for Folder C we want to grant access to Guest Users for read (4)+execute(1)=5

As a conclusion we will change both create mask and directory mask to 0775

Please, do so and replace 0700 in lines 185 and 189 to 0775. As was stated earlier you may also want to add or replace eth0 with your own interface like enp0s8 or what ever output you got when typing IP link show in Terminal. Click on the Save button and close Text Editor. Don't worry about the warning you get in your Terminal. Changes will take effect once we restart samba. Right now there is still more job to be done so it could wait.

2.3 Samba User Folders

2.3.1 Samba 'Root' Folder

In the above mentioned link Folders for Network Share were placed in new /samba/ Folder directly on the root. Here we will place these folders in /media/samba/ instead. So I am preparing the scenario to match the one from the tutorial by first assuring permissions for /media/ to be the same as for root folder '/'. In terminal type

Code: Select all

sudo chown root:root /media/
sudo chmod 755 /media/
then check with

Code: Select all

getfacl /media/
This last command should return following output

Code: Select all

testuser@Mint-20M:~$ sudo chown root:root /media/
[sudo] password for testuser:    
testuser@Mint-20M:~$ sudo chmod 755 /media/
testuser@Mint-20M:~$ getfacl /media/
getfacl: Removing leading '/' from absolute path names
# file: media/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
I am using getfacl <path-to-Directory> (instead of ls -l <path-to-one-Directory-above> which would in our case be 'ls -l /') in order to get clearer picture of permissions, since there could be some masks on a Parent Folder that would reduce/affect actual permissions.

Let us now see what is with our original Folder /media/testuser/ where non-System HDDs are usually mounted by default.

2.3.2 Normal Folder for default Mounting of non-System HDDs

Type in Terminal

Code: Select all

sudo chown testuser:testuser /media/testuser/
getfacl /media/testuser/
This last command should return following output

Code: Select all

testuser@Mint-20C:~$ sudo chown testuser:testuser /media/testuser/
testuser@Mint-20C:~$ getfacl /media/testuser/
getfacl: Removing leading '/' from absolute path names
# file: media/testuser/
# owner: testuser
# group: testuser
user::rwx
user:testuser:r-x
group::---
mask::r-x
other::---
So although it says that users have full rwx (read-write-execute) permissions the actual testuser has only read and execute permission, due to the existing mask r-x. Although it has nothing to do with the tasks set for our tutorial I will mention here that these default settings created for me huge problems when I wanted to use my external HDDs for Network Folder Share. If you don't want to have these kind of troubles, please do as follows, as to make your /media/<your-user-name>/ Folder cleared for future Network Folder Sharing.

type in Terminal

Code: Select all

setfacl -bn /media/testuser/
sudo chmod 775 /media/testuser/
getfacl /media/testuser/
replace testuser with your user-name, of course

Now you will see an output like this

Code: Select all

getfacl: Removing leading '/' from absolute path names
# file: media/testuser/
# owner: testuser
# group: testuser
user::rwx
group::rwx
other::r-x
Following article was to me of crucial assistance in this matter

https://unix.stackexchange.com/questions/339765/how-to-remove-acl-from-a-directory-and-back-to-usual-access-control

So, what ever you might now mount in your default folder for non-System HDDs should be now way more easier to share over local Network especially for situations like in our cases for folders A and C.

2.4 Finally, Samba Folder

We need Samba 'root' Folder (if I am allowed to call it like this) so that samba shares could be functional.

Type in Terminal

Code: Select all

sudo mkdir /media/samba/
sudo chown :sambashare /media/samba/

Code: Select all

getfacl /media/samba/
This should return output like this

Code: Select all

getfacl: Removing leading '/' from absolute path names
# file: media/samba/
# owner: root
# group: sambashare
user::rwx
group::r-x
other::r-x
2.5 Adding group: homeusers
For purposes of Sharing Task for Folder B we need a group of users belonging to the new group homeusers

Type in Terminal

Code: Select all

sudo addgroup homeusers
the Output should be like this

Code: Select all

Adding group `homeusers' (GID 1001) ...
Done.
This GID (Group Identificaton) which is 1001 should be memorized/written down as we will need it later on

2.6 Adding samba share users to the new group 'homeusers'

2.6.1 Adding of user 'john'

Let us now add the first user 'john' and at the same time add him to the group homeusers

a. Type in Terminal

Code: Select all

sudo mkdir /media/samba/john
This shall be the default folder for user john and in our case it will remain empty. If at any point you should need something to be available only for user john place it in this folder and create Folder Rules.

b. next type in Terminal

Code: Select all

sudo adduser --home /media/samba/john --no-create-home --shell /usr/sbin/nologin --ingroup homeusers john
The output should be:

Code: Select all

Adding user `john' ...
Adding new user `john' (1001) with group `homeusers' ...
Not creating home directory `/media/samba/john'.
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for john
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y
If you now want to check the information about user john type in Terminal

Code: Select all

id john
Output should be like

Code: Select all

uid=1001(john) gid=1001(homeusers) groups=1001(homeusers)
As you can read above this user won't be able to log-in into our PC, so it is only restricted to using Samba Network Shares. This is for security reasons.

c. The first mentioned tutorial suggests that we 'round up' this folder for john, so please also type

Code: Select all

sudo chown john:homeusers /media/samba/john/
sudo chmod 2770 /media/samba/john/
As much as it is irrelevant for the tasks in this tutorial, this sets the environment for any future Network Share related/available only to user 'john'

2.6.2 Adding user 'mary'

Now let us do the same for user mary In terminal type same as for john just replacing everywhere with mary.

Code: Select all

sudo mkdir /media/samba/mary
sudo adduser --home /media/samba/mary --no-create-home --shell /usr/sbin/nologin --ingroup homeusers mary
sudo chown mary:homeusers /media/samba/mary/
sudo chmod 2770 /media/samba/mary/
It should look like this

Code: Select all

testuser@Mint-20C:~$ sudo mkdir /media/samba/mary
testuser@Mint-20C:~$ sudo adduser --home /media/samba/mary --no-create-home --shell /usr/sbin/nologin --ingroup homeusers mary
Adding user `mary' ...
Adding new user `mary' (1002) with group `homeusers' ...
Not creating home directory `/media/samba/mary'.
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for mary
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y
testuser@Mint-20C:~$ sudo chown mary:homeusers /media/samba/mary/
testuser@Mint-20C:~$ sudo chmod 2770 /media/samba/mary/
2.7 Let us now make both 'john' and 'mary' also enabled Samba Users with their own samba passwords

Code: Select all

sudo smbpasswd -a john
results with

Code: Select all

New SMB password:
Retype new SMB password:
Added user john.
then type

Code: Select all

sudo smbpasswd -e john
this will give the output

Code: Select all

Enabled user john. 
Same for 'mary'

Code: Select all

sudo smbpasswd -a mary
sudo smbpasswd -e mary
In a real-life situation you can actually have all the real users type their own passwords.

2.8 Now we will finally prepare the Folder where our External USB HDD will be mounted and make the testuser its owner and the group homeusers as group owners

Type in terminal

Code: Select all

sudo mkdir /media/samba/common-shares/
sudo chmod 2775 /media/samba/common-shares/

Code: Select all

getfacl /media/samba/common-shares/
will now return

Code: Select all

getfacl: Removing leading '/' from absolute path names
# file: media/samba/common-shares/
# owner: testuser
# group: sambashare
# flags: -s-
user::rwx
group::rwx
other::r-x
We actually need this second flag as s, because this will enable non-owner users from the group homeusers to actually work and modify the files and directories in this share.

2.9 Let us not forget that testuser also needs to be samba user, like john and mary, and to have its own samba password

Code: Select all

sudo smbpasswd -a testuser
sudo smbpasswd -e testuser
Should we need anybody else to be added to homeusers like john and mary we will simply add them like in 2.6.1 or 2.6.2


CHAPTER 3 MOUNTING EXTERNAL USB HDD of a NTFS type so that you won’t have troubles sharing it


As was mentioned earlier most tutorials are based on sharing your Linux home folders, or home folders created in /samba/<username> or var/samba/<username>, which is all on your system disk and is way easier to organize and to change folder and file permissions, so when it comes to sharing data on your external HDD or even on a non-system internal HDD, which is normal medium where you would actually store and keep something, new Linux Users face a lot of frustrations of how to get the things going. Main issue here is that once you mount a HDD other then System HDD you can not actually change folder and file permissions, so chmod, chown, chgrp or modifications through file explorers are all ineffective. A top of everything there are rules for Parent Folders than can apply to all the subfolders, as well as some ACL permissions. An entire mine field for a newbie.

So let's start by opening application Disks (Press Super/Win key or menu icon at the bottom left corner of the screen, type disks and then click on the icon 'Disks'). It is installed by default in both Cinnamon and Mate Desktops so it is available out of the box.

Click on the USB External Disk icon at the left side of the application. In this case it is named DISK3, 125 GB DRIVE, SMI USB DISK, in your case it will be something else

Image

Now click on Additional partition options and then click on Edit Mount Options …

Image

You will see the default Mount Options like this

Image

Turn off User Session Defaults, check Mount at system startup, change the line without any description (it refers to mounting options) to permissions,x-gvfs-show,uid=1000,gid=1001,suid,dmask=002,fmask=002,nofail

Mount Point field change to /media/samba/common-shares/DISK3

Filesystem Type change to ntfs-3g

Leave 'Identify As' field as it is. Don’t change it by no means!

After that Mount Options should look like this

Image

Click OK
Enter your SUDO password when asked for

Now un-mount and re-mount the disk, so that the changes would be effective. It is done by pressing the rectangle icon (like stop button on an old tape recorder) and than the play/triangle icon, that will be at the same location. Ultimately you will again see the rectangle icon meaning that your disk is mounted.

If you should face any difficulty with remounting make sure that you save and close any application using files related to the content on the disk, then simply unplug it from its USB port and then re-plug it. This will make all the changes effective.

Let us just briefly explain the mounting options used here:

-permissions - I am not exactly sure for this one, but I found it recommended by some posts on Internet so I keep it
x-gvfs-show - This is obligatory for NTFS files so that you could see them with File Explorer
uid=1000 - This says that owner is user with uid=1000 which is the default user, in our case that is testuser
gid=1001 - This says that group owners are from Group with identification 1001, In chapter 2.5 we got this number when we created group homeusers, so this group has group ownership.
suid - this option permits use of flag bits for owner and group, which are defined for the parent folder /media/samba/common-shares/ where we mounted our DISK3
dmask and fmask=002 By this we on the level of files and folders disable modification permission for Guest Users
nofail - if disk is unplugged no error message will be notified, once it is again plugged-in it will be simply mounted, so just a useful option

As was said initially, whenever possible I prefer to use GUI. Other possibility was to change directly /etc/fstab file. Still everything we did with Disks is now written in /etc/fstab so you may open this file and see how it looks. Still, disk identifier is way more easier to set with 'Disks', then to look up with Terminal, and then risk to mistype some character.

If you like to learn more about mounting a drive I would recommend this link

https://help.ubuntu.com/community/Fstab

CHAPTER 4 SETTING SHARING RULES FOR EACH INDIVIDUAL FOLDER
For this tutorial we have created on the mounted External USB HDD (or even a USB Memory Stick) three folders: 'Folder A', Folder B' and 'Folder C' and placed a few print screen images in each one of them.

4.1 Setting Folder A so that it can be accessed with full permissions only by its owner 'testuser'

Open your default File Browser (you can simply Press Super/Win + E).

Then when it opens click on the DISK3 icon at the left side of 'Files' window

When you see all the three folders listed (if you haven't done it earlier now add three folders: 'Folder A', Folder B', 'Folder C' and put some insignificant files in each one of them) right click, one by one, on each one of them and select 'Sharing options'. (If in MATE you don't see this option log-out then log-in. If you missed to install caja-share then do it now 'sudo apt install caja-share' log-out, log-in).

Folder A set like this

in Cinnamon
Image

in MATE

Image

Linux Mint is known for warning about Folder Share, even when everything is just fine, but don't worry about it. If at any point you are asked should some additional permissions be added automatically for you, just click 'yes'

Folder B set like this

Image

and Finally, Folder C like this

Image

In each particular case press 'Create Share' and if requested type your sudo password.

Let us now explain what kind of options we were given here

a. By clicking on Share this Folder we are enabling both the owner and the group owners to access this folder. Owner gets the full access (unless said differently in general samba rules, see above Chapter 2.2 for file and folder masks), while group members only get read-execute access by this particular rule, also general rules are applicable for group owners.

b. By checking on 'Allow others to create and delete files in this folder' we further permit everyone with access to also modify the files (however this is further decided by File and Folder Permissions)

c. By selecting Guest access, we permit guest users to connect to the folder

Let's try now to summarize several levels on which access is decided:

1. General samba rules in /etc/samba/smb.conf, especially 'Create Folder Mask and Create File Mask' (Initial values for Folder and File masks are set at 0700, which means that only owner can be granted access, therefore we had to modify this to 0775)
2. Individual samba rules (there are classic shares and user shares). In our case we used user shares rules since we had GUI, more will be said bellow, while classic shares are similar to user shares but are written at the end of /etc/samba/smb.conf file. In the past there was an application system-config-samba that represented a GUI for easier work with classic shares, however many Ubuntu Forums are warning that this has not been maintained for a longer period and is not recommended for use any more. Furthermore, usershares work just fine and it is not even necessary to use GUI for classic shares. Veteran Administrators got use to write classic share rules directly to smb.conf, so they are not affected - they can keep doing it.
3. Parent Folder Flags or masks
4. Disk Mounting Rules and Masks
5. File and Folder Permissions.

If we now compare our original tasks for three folders we will see that it is not exactly reached for folder A, since also group users from homeusers can have an access. There is an easy way to remedy this last discrepancy. Furthermore, homeusers could also access Folder C, but without write permission, so I prefer to leave it like this, since they won't be able to modify anything it is no big difference if they are loged-in (samba loged-in) as Guests or as john and mary. An additional reason will be explained later when we come to accessing to these folders from a Windows PCs.

By clicking on the Folder and selecting Folder Mount Options we have created rules for so called samba User Shares, as is already mentioned. The Samba User Shares rules are saved in the following Folder on your Ubuntu based PC:

Code: Select all

/var/lib/samba/usershares/


and these rules have same folder names but with all small letter, like on this picture.

Image

type in terminal

Code: Select all

xed /var/lib/samba/usershares/folder*
and you will be able to see all these rules for our folders (since they all begin with folder...) and also to edit them, unless you mistakenly prefixed upper command with sudo, which should not be done in this particular case. If you need to see just a particular rule you would need to type like this, since we have space in our folder name

Code: Select all

xed "/var/lib/samba/usershares/folder A"
Image

4.4 Removing users from 'homeusers' group from access to folder A

We now just need to make a slight modification in the rules for folder A, just replace one ace with zero, like on the following two pictures, this will actually remove permission for users in the group homeusers to access Folder A and only leave access to the owner

Image

Image

Click Save and then close all three rules' files opened in editor. If you prefer to make same kind of modification also for folder C it is up to you.


4.4.1 Samba services restart


Finally we must not forget to restart samba services smbd and nmbd, so that everything we did becomes effective and so that we can proceed to testing. So type in Terminal

Code: Select all

sudo service smbd restart
sudo service nmbd restart

4.5 Initial testing


Network Shared Folders can be accessed in two ways

a) By IP address
b) By PC name (From the point of view of someone accessing a shared folder this becomes Samba Server name, please don't be confused here)

Additionally, Machines with Shared Folders can be visible or invisible when you click in Windows Folder Explorer on Network icon, or in Linux File Manager on Browse Network icon

Furthermore, even if sometimes your PC name appears either in Windows or Linux, by clicking on it you might gain access or get an error like 'unable to mount to selected location'.

Still more, you may be required to type full path to the Shared Folder, not just to a Samba server with several shared folders. So, still some mines ahead of us, but we are getting closer and closer to our goal.

Let us see where do we stand now, before we apply some improvements to 'visibility issues'. Just don't be afraid, I want to introduce you to all the twists and turns I have learnt about.

We will deal here with many of the above cases.


4.5.1 Accessing Shared Folder by PC name and by IP address


a) Ubuntu, Linux Mint, probably most other Linux distros

Generally you need to type in the folder address field in your File Manager (on Ubuntu based distros press Ctrl + L or icon with '.' or 'pencil' in Linux Mint if you don't see this address field but icons to Folders)

Code: Select all

smb://server-name.local/
server-name is practically the name of the PC which is hosting shared folders.

In our case smb://Mint-20C.local/ and smb://Mint-20M.local/

if you want to access by ip adress

Code: Select all

smb://ip-address/
in our case

smb://10.1.3.62/ and smb://10.1.3.64/

Unless other Linux PCs on your home network had had some modification of smb.conf file, your share won't be available by merely giving the server-name or IP address. These two PCs from our example might only be 'visible'. Yes, another mine, but just a little bit more patience!

b) If you try now with Windows 7 or Windows 10 to click on Network icon (bottom left side of File Explorer) you will see none of our two Mint machines with shared folders.

If you type in the address field of Windows Explorer

\\Mint-20C\
or
\\Mint-20M\

Windows 7 will not be able to access anything, while Windows 10 will be the only system able at this point to access both servers by their name and show Folders for Share, but still you are the one who needs to type properly these names.

If you type in address field

\\10.1.3.62\
or
\\10.1.3.64\

In this case both Windows 7 and Windows 10 will be able to access both our servers by their IP address and present all the folders for Share, but still you are the one who needs to type properly these IP addresses.

Please, note, that Windows uses backslashes, while Linux uses forward-slashes for network folder addresses. Also Linux has smb: as a prefix.

c) If we now get back to Ubuntu and Linux Mint and if we type full path to a shared Folder, for example

smb://Mint-20C.local/Folder A
or
smb://10.1.3.62/Folder A

only now shall we be able to connect to that Folder. So folder sharing actually works but the 'visibility' is an issue.

To conclude, although we did everything to properly set Shared Folders, it is rather difficult to access them, especially by a Linux File Manager, and especially for a total beginner.

4.6.1 Improving 'visibility' between Shared Folder on Linux PCs

We can significantly improve 'visibility' and easier connectivity between Linux machines by modifying smb.conf file

Type in terminal on each Linux Machine (so not just two from our example, but on any other in your home network)

Linux Mint Cinnamon and MATE

Code: Select all

sudo xed /etc/samba/smb.conf
Ubuntu with default Unity Desktop

Code: Select all

sudo gedit /etc/samba/smb.conf
Ubuntu-mate

Code: Select all

sudo pluma /etc/samba/smb.conf
For other Linux distributions check yourself what is the default text editor and where is smb.conf placed

In any case behind line which is initially line 29 workgroup = WORKGROUP add following lines

client max protocol = SMB3
# client min protocol = NT1
server max protocol = SMB3
server min protocol = NT1
# wins support = yes

Many will immediately object why putting lines with hashtag (#) when they are just comments and don't count, but these are for users with earlier versions of Windows, they can uncomment these two lines (remove hashtags) and see if this might help them. Experiments that I conducted on Windows 7, Windows 10, MacOS Catalina, Android cell phone and Android Tablets and various Linux distros showed that maximum improvement is achieved through these three options:

client max protocol = SMB3
server max protocol = SMB3
server min protocol = NT1

So, please, paste there three or all five of those lines in your smb.conf file on all of your Linux PCs, click Save and close the editor.

client max protocol practically says that when your PC is accessing another PC it will try with Samba 3 Protocol
Other two lines say that when your PC is accessed by another PC, your PC will permit any protocol from SAMBA 1 (NT1) up to SAMBA 3, this way your PC is more flexible, but also more exposed. Modern Administrators don't like actually to have all the shared folders easily visible so that random users could play with usernames and passwords. It is up to you to decide what is optimal in your own situation. Windows PCs, actually, immediately submit credentials for the loged-in users so Administrators regulate 'visibility' of Shared Folders based on these initial credentials. Linux Mint, on other side, doesn't do that initially, but only when you click on a shared folder's icon.

Now, of course, restart samba services on all your Linux machines in order for these last modifications to be effective

Code: Select all

sudo service smbd restart
sudo service nmbd restart
4.6.2 Improving 'visibility' between Shared Folder on Linux PCs on one side and Windows 10 machines on other side, for Ubuntu based machines

We have this article to help us with more easily accessing our folder from Win10

https://devanswers.co/discover-ubuntu-machines-samba-shares-windows-10-network/

Following this article type in Terminal following lines, one by one

Code: Select all

cd /tmp
wget https://github.com/christgau/wsdd/archive/master.zip
unzip master.zip 
sudo mv wsdd-master/src/wsdd.py wsdd-master/src/wsdd
sudo cp wsdd-master/src/wsdd /usr/bin
sudo cp wsdd-master/etc/systemd/wsdd.service /etc/systemd/system
sudo xed /etc/systemd/system/wsdd.service
The last command will open a configuration file in text editor

Basically you need to replace (delete) line 12 stating

Code: Select all

DynamicUser=yes
with following lines

Code: Select all

; Replace those with an unprivileged user/group that matches your environment,
; like nobody/nogroup or daemon:daemon or a dedicated user for wsdd
; User=nobody 
; Group=nobody
Then save and close your editor

Then proceed with Terminal

Code: Select all

sudo systemctl daemon-reload
sudo systemctl start wsdd
sudo systemctl enable wsdd

Log-out, log-in

4.7 Finally, let's see the full extent of our achievements

a) From Linux Mint Cinnamon/Mate or Ubuntu we now see both samba servers: Mint-20C and Mint-20M when we click on Network icon. By clicking on the icon we are shown all three shared folders, we can access them with credentials as per our wish.

During this testing it is recommended that you don't save passwords. Best always click on forget immediately.

b) You can also type now:

smb://10.1.3.62/ or smb://10.1.3.64/

and you will again see all three folders.

So, now everything works between Linux machines and they see what is shared on every other Linux machine.

While testing you can easily unmount any mounted Folder and then mount it with different username and password.

You can be mounted simultaneously to different folders on a same machine with different credentials (username and password)

c) From Win10

Now Shared Folders and Servers with them are visible in Windows 10 when you click on Network icon

If you like illustrations see this gallery

https://imgur.com/a/6LBvHIy

One thing, however, should be noted regarding both Win7 and Win10. You cannot connect to two different Shared Folders on a single Samba Server with two different credentials. This complicates somewhat testing of our examples. Don't save password and if you need to reset last password and username for a Samba Server you have connected to, you need to open Windows Terminal (CMD) as Administrator and type following two lines (goes both for Win7 and Win10)

Code: Select all

net stop workstation /y

net start workstation
It is illustrated on last two pictures in the gallery above

Of course you can also access by IP address, but this was possible even before last changes.

d) From Win7

This Windows distro has been, obviously, marginalized, so I wasn't able to find anything to recommend. The only link I actually found has crashed my Win7 so I don't even want to go there - let us leave this mine "un-shared".

So the only way is to go through IP address

\\10.1.3.64\ or \\10.1.3.62\ in our case

If someone knows better please post a solution and point me there

e) From MacOS I was only able to access through IP address.

Right-click on Finder, select 'Connect to Server', then type IP address, then credentials, select Folder(s) to mount to. Illustrations are in this here gallery.

https://imgur.com/a/KYlPS4S

In general, I don't work with MacOS, so just know some basics.

From Android devices you can install free applications from Play Store like Cx File Explorer, File Manager +

These applications make it very easy to connect to a Shared Folder from your Android device.

Thanks for patience for those who were able to reach the end of this tutorial. Hope it does help someone.
Last edited by JezekiljMonk on Sat Apr 02, 2022 11:41 am, edited 4 times in total.
acsey
Level 1
Level 1
Posts: 18
Joined: Thu Apr 01, 2010 8:31 pm

Re: Sharing Folders On External Usb Hdd For Total Beginners On Freshly Installed Mint 20.2 Cinnamon And Mate

Post by acsey »

Thank you my man. I had really given up on sharing files with linuxmint until this.

I spent so, so much time trying to get it to work. Now it does.

I have mixed emotions here...happy that it works and pretty disappointed that this is what it takes.

Wow, keep it up dude.
JezekiljMonk
Level 3
Level 3
Posts: 105
Joined: Mon Dec 30, 2019 7:33 am
Contact:

Re: Sharing Folders On External Usb Hdd For Total Beginners On Freshly Installed Mint 20.2 Cinnamon And Mate

Post by JezekiljMonk »

I tested this tutorial recently on LMDE5, thought I should point out what is not the same, and there isn't much of it, but still.
Some of it might be related to recent updates in SAMBA.

1. By adding users to samba with

Code: Select all

sudo smbpasswd -a <username>
sudo smbpasswd -e <username>
This did not automatically add <username> to 'sambashare' group

So I had to make additional line

Code: Select all

sudo usermode -aG <username> sambashare
I also had to reboot or log-out and back log-in for these changes to work.

2. Process of installing wsdd did not work both on Debian 11 and on LMDE5, but the only thing you need to do extra is in chapter 4.6.2

Once you open wsdd.service for editing with (xed id default in LMDE5, but you might also be using gedit, or any other text editor)

Code: Select all

sudo xed /etc/systemd/system/wsdd.service
Overwrite everything with following

Code: Select all

[Unit]
Description=Web Services Dynamic Discovery host daemon
Documentation=man:wsdd(8)
; Start after the network has been configured
After=network-online.target
Wants=network-online.target
; It makes sense to have Samba running when wsdd starts, but is not required.
;Wants=smb.service


[Service]
Type=simple
ExecStart=/usr/bin/wsdd --shortlog
; Replace those with an unprivileged user/group that matches your environment,
; like nobody/nogroup or daemon:daemon or a dedicated user for wsdd
; User=nobody 
; Group=nobody
;AmbientCapabilities=CAP_SYS_CHROOT
;ExecStartPre=/usr/bin/install -d -o nobody -g nobody -m 0700 /run/wsdd/chroot
;ExecStopPost=rmdir /run/wsdd/chroot
[Install]
WantedBy=multi-user.target
Then save, close and proceed

Code: Select all

sudo systemctl daemon-reload
sudo systemctl start wsdd
sudo systemctl enable wsdd
The rest remains the same
Post Reply

Return to “Tutorials”