How to Set Up a Basic Samba File Server on Ubuntu
Samba is a free software re-implementation of the SMB/CIFS networking protocol that allows file sharing between different operating systems, including Linux and Windows. This guide will walk you through the steps to set up a basic Samba file server on Ubuntu.
← BackStep 1: Install Samba
First, you need to install Samba on your Ubuntu server. Open your terminal and run the following command:
sudo apt update
sudo apt install samba
Step 2: Create a Shared Directory
Create a directory that you want to share over the network. For example, you can create a directory called /srv/samba/share
:
sudo mkdir -p /srv/samba/share
Now, set the correct permissions for the directory to allow read and write access:
sudo chmod 777 /srv/samba/share
Step 3: Configure Samba
To share the directory over the network, you need to configure Samba by editing its configuration file. Open the Samba configuration file:
sudo nano /etc/samba/smb.conf
Scroll to the bottom of the file and add the following configuration to create the shared folder:
[Share] path = /srv/samba/share read only = no browsable = yes guest ok = yes force user = nobody
This configuration allows guests (unauthenticated users) to access the share with read and write permissions. Save the file and exit the editor (press Ctrl + X
, then press Y
, and hit Enter
).
Step 4: Restart Samba Service
After making changes to the Samba configuration, restart the Samba service to apply them:
sudo systemctl restart smbd
Step 5: Allow Samba Through the Firewall
If you are using a firewall on your Ubuntu server, you need to allow Samba traffic through. You can do this by running the following commands:
sudo ufw allow samba
Check the firewall status to ensure that the rules have been applied:
sudo ufw status
Step 6: Access the Shared Folder
Now that Samba is configured, you should be able to access the shared folder from another machine. On a Windows machine, open the File Explorer and enter the following address in the address bar:
\\your_server_ip\Share
On a Linux machine, you can access the shared folder using the file manager or by mounting the share with the mount
command.
Step 7: Troubleshooting
If you are having trouble accessing the share, check the Samba logs for errors:
sudo tail -f /var/log/samba/log.smbd
Conclusion
That’s it! You have successfully set up a basic Samba file server on Ubuntu. You can now share files between Ubuntu and other systems, such as Windows and macOS, using the SMB protocol. If you want more advanced configurations, consider setting up user authentication or controlling access with Samba's various options.
← Back