Sharing files across devices in a home network is a common requirement for many people who need to access their documents, media, or other files from multiple computers. One of the most efficient ways to do this in Ubuntu is by using Samba, a protocol that enables Linux, Windows, and macOS devices to communicate over a network and share files seamlessly.
Run a quick update by running the following command in a terminal window before installing Samba.
sudo apt update
sudo apt upgrade
To install Samba, run the following command.
sudo apt install samba
To verify that Samba is installed correctly, run the following command.
samba --version
You should see the installed version of Samba.
Now that Samba is installed, we need to configure it by editing the Samba configuration file located at /etc/samba/smb.conf
.
Open the configuration file in your preferred text editor. For example, to use Gedit.
sudo gedit /etc/samba/smb.conf
Scroll down to find the section labeled [homes]
or [share]
and add the following configuration to create a new share.
[SharedFolder]
comment = Ubuntu File Share
path = /path/to/shared/directory
browseable = yes
read only = no
guest ok = yes
force user = your-username
[SharedFolder]:
This is the name of the share. You can replace it with any name you’d like.comment:
A short description of the share.path:
The full path to the directory you want to share. Replace/path/to/shared/directory
with the actual path.browseable:
When set toyes
, the shared folder will be visible to other machines on the network.read only:
When set tono
, it allows write access to the share.guest ok:
Allows guests (unauthenticated users) to access the share. Set this toyes
if you want everyone on your network to access it without a username/password.
Save and exit the file by pressing CTRL + X
, then Y
, and then Enter
to confirm changes.
Samba requires that the directory you’re sharing has the appropriate permissions for other users on the network to access it.
To ensure the permissions are correct, run the following command.
sudo chmod 755 /path/to/shared/directory
If you want to set stricter permissions, you can control access by creating a specific user group or limiting access based on usernames. To set permissions to a specific user, run the following command.
sudo chown your-username:your-group /path/to/shared/directory
Replace your-username
and your-group
with your actual username and group.
If you want to require authentication to access the shared folder, you’ll need to create Samba users.
Add a new user for Samba (if the user already exists in Ubuntu, you can skip this step).
sudo adduser username
Set a Samba-specific password for this user.
sudo smbpasswd -a username
Replace username
with the actual username you want to grant access.
Restart Samba by running the following command.
sudo systemctl restart smbd
sudo systemctl restart nmbd
If you have UFW enabled
, allow Samba traffic:
sudo ufw allow samba
How to access the shared folder from another Ubuntu device:
Open the Files application.
In the sidebar, click on Other Locations.
In the Connect to Server field, type the following and press Enter.
smb://<Ubuntu-IP-Address>/<SharedFolder>
Replace <Ubuntu-IP-Address>
with the IP address of your Ubuntu machine, and <SharedFolder>
with the name you specified in the Samba configuration file.
How to access the shared folder from Windows device:
Open File Explorer.
In the address bar, type.
\\<Ubuntu-IP-Address>\<SharedFolder>
Replace <Ubuntu-IP-Address>
with the IP address of your Ubuntu machine, and <SharedFolder>
with the name you specified in the Samba configuration file.
Press Enter.