How to share a folder on the local network (Ubuntu 22.04)
Here I want to simply share the steps required to share a folder over local network (tested on Ubuntu 22.04). One useful use case would be to use an external drive for backup files from your phone or tablet over local network (house wifi).
Step1: Install the required packages
sudo apt update
sudo apt install samba
confirm the installation was successful by running:
whereis samba
the output should be
samba: /usr/sbin/samba /usr/lib/samba /etc/samba /usr/share/samba /usr/share/man/man7/samba.7.gz /usr/share/man/man8/samba.8.gz
Step2: Create a folder you want to share, somewhere on your machine or external drive
Step3: Edit Samba config file
run the following command to edit the samba config file:
sudo nano /etc/samba/smb.conf
in the smb.conf file you will see a section name [sambashare]. This is the name of the shared resource by default. You can either edit this section to route to your local folder or duplicate it. You can add as many sections as you want to share folders (one shared resource for each shared folder). The shared resource config should be like:
[localstorage]
comment= Local Storage folder to share via network
path = <PATH_TO_FOLDER>
create mask = 0664
force create mode = 0664
directory mask = 0775
force directory mode = 0775
public = yes
read only = no
browsable = yes
To get the <PATH_TO_FOLDER> you can run the following command in a terminal inside the folder.
pwd
Step4: Set samba username/password
run:
sudo smbpasswd -a <username>
<username> should be the operating system (here Linux) username. After running the command, you’ll be asked to enter the samba password. Keep note of it since you will need it later to connect to this folder.
Step5: Restart samba so settings take effect
run:
sudo service smbd restart
sudo ufw allow samba
And you are done with the settings. You don’t need to manually edit share/permission configs via Linux file manager.
Each time you want to share a new folder, you have to add a new section in samba config (Step3) and restart samba (Step5) to activate the new config.
Step6: Access the folder
To access the folder first you can check via Linux file manager. Go to Other Locations and open the created network (often named after your machine). You have to see the shared folder there. Open it and enter username/password set in step4. Note again the username is your os username but the password is the samba password you have already set.
Connect to the folder via phone (connected to the same wifi) — tested on Samsung S22 Ultra:
In Samsung File Manager go to Network Storage and add a new Network Drive (SMBv2/SMBv3). It will automatically detect your drive. Then you have to set the username and the password you set above. You will be able to add the folder to your phone and upload/download files. Other phones or operating systems (windows/mac) should have a similar procedure, though not exactly as what I wrote).