Setting Up a Samba Server on Ubuntu: A Complete Guide
Accessing File in Same Network using LAN

Setting Up a Samba Server on Ubuntu: A Complete Guide
Samba is a powerful open-source software suite that provides file and print services to SMB/CIFS clients, such as Windows machines. This guide will take you through the process of setting up a Samba server on an Ubuntu machine, both for public and password-protected shared folders. We will also cover how to configure the necessary folder permissions to ensure the right level of access for each type of share.
1. Installing Samba on Ubuntu
To begin, we need to install the Samba package on your Ubuntu machine. Open a terminal and follow these steps:
Step 1: Update Your System
Before installing any software, it’s a good idea to ensure that your system is up-to-date:
sudo apt update
sudo apt upgrade
Step 2: Install Samba
Now, install the Samba package using the following command:
sudo apt install samba
Once the installation is complete, Samba should be installed and ready to configure.
Step 3: Check the Installation
To confirm that Samba is installed successfully, check the version:
smbd --version
This will display the installed Samba version.
2. Configuring Samba Shares
Now, let’s configure two types of shared folders: one public (no password required) and one password-protected (requires authentication).
Step 1: Create Folders for Sharing
Let’s create two folders for sharing:
# Create a public folder
sudo mkdir /home/ubuntu/shared_public
sudo chmod -R 0777 /home/ubuntu/shared_public
# Create a password-protected folder
sudo mkdir /home/ubuntu/shared_private
sudo chmod -R 0775 /home/ubuntu/shared_private
Now we have:
/home/ubuntu/shared_public
: This folder will be accessible without a password./home/ubuntu/shared_private
: This folder will require authentication.
Step 2: Edit the Samba Configuration File
The Samba configuration file is located at /etc/samba/smb.conf
. Open it in your preferred text editor (e.g., Nano):
sudo nano /etc/samba/smb.conf
Step 3: Add Share Definitions to the Configuration File
Next, add the definitions for the shared folders at the end of the smb.conf
file. This is where we define how the folders will be shared and whether they will be public or require a password.
For the Public Folder:
[PublicShared]
path = /home/ubuntu/shared_public
browsable = yes
writable = yes
guest ok = yes
read only = no
force user = ubuntu
Explanation:
guest ok = yes
: Allows public (unauthenticated) access.read only = no
: Enables read/write access to the folder.force user = ubuntu
: Ensures that files are created by theubuntu
user, keeping ownership consistent.
For the Password-Protected Folder:
[PrivateShared]
path = /home/ubuntu/shared_private
browsable = yes
writable = yes
guest ok = no
read only = no
valid users = ubuntu
Explanation:
guest ok = no
: Disables guest access.valid users = ubuntu
: Restricts access to theubuntu
user. You’ll need to set up Samba authentication for this user.
Step 4: Restart Samba
Once you’ve added the configurations, restart the Samba service to apply the changes:
sudo systemctl restart smbd
3. Set Up Samba User for Password-Protected Share
If you want to protect the private share, you need to create a Samba user. In this case, the ubuntu
user will be used, but you may also create other users if needed.
To add the ubuntu
user to Samba, run:
sudo smbpasswd -a ubuntu
You will be prompted to enter and confirm a password for the user. This password will be required when accessing the password-protected folder.
After adding the user, enable the Samba user:
sudo smbpasswd -e ubuntu
Now, the private folder will require the ubuntu
user’s Samba credentials to access.
4. Folder Permissions
Permissions are essential for controlling who can access, modify, or delete files within your shared folders. Here’s how we can manage folder permissions:
For the Public Folder:
The public folder allows anyone on the network to read, write, and create files. To ensure this, we’ll use 0777
permissions, which grant read, write, and execute access to everyone:
sudo chmod -R 0777 /home/ubuntu/shared_public
For the Private Folder:
The private folder is intended to allow access only to authenticated users (in this case, the ubuntu
user). To ensure only the user can read/write, while others have limited access, use 0775
permissions:
sudo chmod -R 0775 /home/ubuntu/shared_private
This setup allows the ubuntu
user and members of the same group to have full access, while others can only read files (but cannot delete them).
Setting Permissions for Specific Users (Optional):
If you want to set up more granular access control (for example, different permissions for different users or groups), you can use Access Control Lists (ACLs). For example, to give the ubuntu
user full access to the private folder and allow others only read access:
sudo setfacl -m u:ubuntu:rwx /home/ubuntu/shared_private
sudo setfacl -m o::r-x /home/ubuntu/shared_private
This configuration gives ubuntu
full control while limiting others to read-only access.
5. Accessing the Shared Folders
Once everything is configured and Samba is restarted, you can access the shared folders from other machines on the network.
On Windows:
Open the File Explorer and type the following in the address bar:
\\<Ubuntu_IP>\PublicShared
For the password-protected folder, you’ll need to enter the ubuntu
user’s Samba credentials:
\\<Ubuntu_IP>\PrivateShared
On Linux/macOS:
You can access the shared folders using the following paths:
- For the public folder:
smb://<Ubuntu_IP>/PublicShared
- For the private folder:
smb://<Ubuntu_IP>/PrivateShared
6. Testing and Troubleshooting
If you encounter issues with accessing the shared folders:
- Check Samba status: Ensure the Samba service is running properly:
sudo systemctl status smbd
- Firewall: Ensure that your firewall is configured to allow Samba traffic. On Ubuntu, use:
sudo ufw allow samba
- Permissions: Verify that folder permissions are set correctly. Sometimes, incorrect folder permissions can cause access issues.
- Samba Logs: You can check Samba logs for more detailed error messages:
sudo tail -f /var/log/samba/log.smbd
Conclusion
Setting up a Samba server on Ubuntu is a great way to share files between different operating systems on a local network. In this guide, you learned how to create both public and password-protected shares, configure folder permissions, and ensure the right level of access for different users.
Whether you’re setting up a file server for a small office, home network, or testing environment, Samba offers the flexibility and features needed to meet a wide variety of use cases.
Let me know if you have any questions or need further assistance with your Samba setup!