If you’ve ever worked in a company, chances are you’ve accessed a shared directory is pretty high. Usually those shared folders are from someone else’s desktop or maybe even a server.
Also: 8 Things You Can Do With Linux That You Can’t With MacOS Or Windows
Did you know that you can do the same on your home network, no matter what operating system you use? If you have multiple computers on your home or business network and want to be able to share files and folders from within your Linux operating system, the process isn’t as difficult as you might think. And while some Linux distributions strive to make this a point-and-click affair, they tend to fall short.
That’s when you need to go back to Samba and the terminal window. But I’m going to show you how this is done in clear and simple terms. All you will have to do is copy and paste some commands and a configuration. Once you’re done, anyone on your home or business LAN should be able to access those shared folders and files.
Also: The best Linux laptops you can buy
For this to work, you will need a running Linux instance and a user with sudo privileges. I’ll demonstrate the process with the easy-to-use Ubuntu Desktop 22.04, but the process will be the same for most distributions (the only exception is installing Samba).
With that said, let’s share.
The first thing to do is install Samba. We’re going to do it from the command line, so log in to your Linux desktop and open your terminal window app. With the terminal open, install Samba with:
sudo apt-get install samba -y
If you’re on a Fedora-based (or RHEL-based) desktop, that installation would be:
sudo dnf install samba -y
You may find that Samba is already installed by default. Either way, you’re good to go.
Start and enable the Samba service with:
sudo systemctl enable --now smbd
Some Linux file managers allow you to share folders directly from the GUI application. I’m going to share with you the manual process, in case your file manager doesn’t include that option.
Creating the share
Let’s say the folder you want to share is the Public folder in your home directory (so /home/USER/Public – where USER is your username). Returning to the terminal window, we are going to open the Samba configuration file, using the nano text editor, with the command:
sudo nano /etc/samba.smb.conf
At the bottom of that file, paste the following:
[Public] path = /home/USER/Public browsable = yes writable = yes read only = no force create mode = 0666 force directory mode = 0777
Where USER is your username.
Note: If you do not want other users to be able to make changes to files and folders, set write to no.
Also: How to open files from Samba share in LibreOffice
Save and close the file. Restart Samba with:
sudo systemctl restart smbd
At this point, your Samba share will be visible to the network, but will not allow anyone to access it. Let’s fix that.
I will assume that you are the only user on your Linux box. However, you don’t want to give your login credentials to other users, and you don’t want to allow anonymous access to the shared directory (as that could be a security issue). So what do we do? We are going to create a new account on your machine that others can use to access your files and folders.
In the terminal window, create a user named guestshare with the command:
Give that user a unique and strong password, name them Samba Guest (or something like that), and then just hit Enter on your keyboard for the remaining questions.
Next we need to enable that user for Samba, so run the following two commands:
sudo smbpasswd -a guestshare sudo smbpasswd -e guestshare
The first command above adds the user and the second command enables the user.
After entering the first command, you will be prompted to add a new password for Samba. You can use the same password that you added when you created the guestshare account.
Also: How to replace Windows with Linux Mint on your PC
Any user on your network should now be able to access that folder using the guestshare credentials.
And that’s all there is to creating a shared folder in Linux from your user’s home directory. Users can not only view the files and folders they contain, but can also create and modify them.