Sharing files between different operating systems can sometimes feel like a hassle. Fortunately, Samba makes it easy to share files and printers across a network, allowing Windows, macOS, and Linux machines to communicate seamlessly.
This guide will walk you through setting up a basic, password-protected Samba file share on a Linux system (specifically using Ubuntu/Debian-based commands).
Step 1: Install Samba π
First, you need to update your package list and install the Samba software. Open your terminal and run:
sudo apt update
sudo apt install samba -y
To verify that Samba installed correctly, you can check its status:
sudo systemctl status smbd
Step 2: Create a Shared Directory π
Next, let’s create the folder you want to share over the network. We’ll create a folder called sambashare in your home directory.
mkdir ~/sambashare
Step 3: Configure the Samba Share π
Samba’s configuration is handled by a single file located at /etc/samba/smb.conf.
Before making changes, it’s always a good idea to back up the original configuration file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
Now, open the configuration file in a text editor (like nano):
sudo nano /etc/samba/smb.conf
Scroll all the way to the bottom of the file and add the following lines:
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes
Note: Replace username with your actual Linux username.
Save and exit the file (in nano, press CTRL+O, Enter, then CTRL+X).
Step 4: Set Up a Samba User Password π
Samba uses its own password management system. You need to add your current Linux user to Samba and set a password.
sudo smbpasswd -a username
Note: Again, replace username with your actual Linux username. You will be prompted to create and confirm a password.
Step 5: Restart the Samba Service π
For your new configuration to take effect, you need to restart the Samba service:
sudo systemctl restart smbd
(Optional) If you have a firewall enabled (like UFW), you’ll need to allow Samba traffic:
sudo ufw allow samba
Step 6: Connect to Your Share π
Your Samba server is now up and running! Here is how to access it from different devices:
From Windows: π
- Open File Explorer.
- In the address bar at the top, type
\\IP_ADDRESS\sambashare(ReplaceIP_ADDRESSwith your Linux machine’s local IP address, which you can find by typingip ain the terminal). - When prompted, enter the username and the Samba password you created in Step 4.
From macOS: π
- Open Finder.
- Go to the menu bar and click Go -> Connect to Server (or press
Cmd + K). - Type
smb://IP_ADDRESS/sambashareand click Connect. - Enter your Samba credentials.
From another Linux machine: π
Open your file manager and look for a “Network” or “Other Locations” tab, then type:
smb://IP_ADDRESS/sambashare
Congratulations! You’ve just set up your own cross-platform file server using Samba.