X
Tech
Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.

Close

How to share folders to your network from Linux

If you need to share files and folders with other users on your network from your Linux desktop, follow these steps to walk you through the process.
Written by Jack Wallen, Contributing Writer
Person typing on a laptop
Nitat Termmee/Getty Images

If you've ever worked in a business, the likelihood of you having accessed a shared directory is pretty high. Usually, those shared folders are from someone else's desktop computer or maybe even a server.

Did you know that you can do the same thing on your home network, regardless of what operating system you use? If you have several computers on your home or business network, and you want to be able to share files and folders from your Linux operating system, the process isn't nearly as hard as you might think. And although some Linux distributions strive to make this a point-and-click affair, they tend to fall short of the mark. 

Also: The best Linux laptops

That's when you need to turn to Samba and the terminal window. But I'm going to show you how this is done in simple terms. All you'll have to do is copy and paste a few commands and a configuration. Once it's finished, anyone on your home or business LAN should be able to access those shared folders and files.

How to share folders from Linux

What you'll need: To make this work, you'll need a running instance of Linux and a user with sudo privileges. I'll demonstrate the process with the user-friendly Ubuntu Desktop 22.04, but the process will be the same for most distributions (the only exception being the installation of Samba). 

With that said, let's get to the sharing.

1. Install Samba

The first thing we must do is install Samba. We're going to do that from the command line, so log into your Linux desktop and open your terminal window application. 

Also: How to install Linux applications from the command line

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 might find that Samba is already installed by default. Either way, you're ready to continue.

2. Start the service

Start and enable the Samba service with:

sudo systemctl enable --now smbd

Some Linux file managers allow you to share folders directly from within the GUI application. 

Also: 8 things you can do with Linux that you can't do with MacOS or Windows

I'm going to share with you the manual process, on the off-chance your file manager doesn't include that option.

Creating the share

1. Edit the smb.conf file

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). Back at the terminal window, we're 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 don't want other users to be able to make changes to files and folders, set writable to no. 

Also: Can't remember the Linux command you just ran earlier? Let history repeat itself

Save and close the file. 

2. Restart Samba

With the configuration file edited, it's time to restart Samba with:

sudo systemctl restart smbd

At this point, your Samba share will be visible to the network, but won't allow anyone to access it. Let's fix that.

3. Add your user to Samba

I'm going to assume you are the only user on your Linux machine. However, you don't want to be handing out 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? Let's create a new account on your machine that can be used by others to access the files and folders.

At the terminal window, create a user named guestshare with the command:

sudo adduser guestshare

Give that user a unique and strong password, name it Samba Guest (or something like that), and then just hit Enter on your keyboard for the remaining questions.

4. Enable the user for Samba

Next, we have 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'll be prompted to add a new password for Samba. You can use the same password you added when you created the guestshare account.

Also: How to open files from Samba share in LibreOffice

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 on Linux from within your user home directory. Not only can users see the files and folders within, but they can also create and modify them.

Editorial standards