Samba is an opensource program that was developed for file sharing and printing over network using SMB protocol. Now a days it is basically used for providing Linux file system shares to accessible on Windows systems.
This tutorial will help you step by step guide to install and configure Samba server on Ubuntu to share files and folders across different computers on a network. The steps are simple and written in easy-to-understand language, so anyone can follow along.
Step-by-Step Guide to Install and Configure Samba
Follow the below steps to complete setup for a working Samba server on your Debian based systems.
Step 1: Update Your System
Before you begin, make sure your system is up to date. Open a terminal and run these commands:
sudo apt update
sudo apt upgrade
This will make sure that your system has the latest security patches and software versions.
Step 2: Install Samba
The samba packages are available under default repositories in all Debian based operating systems. Once your system is updated, you can install Samba by using the following command:
sudo apt install samba
This command installs the Samba server and client packages on your Ubuntu machine.
Step 3: Check Samba Status
After installation, you can check if the Samba service is running the following command:
sudo systemctl status smbd
If Samba is running, you’ll see something like “active (running)â€. If it’s not running, you can start it using:
sudo systemctl start smbd
Also make sure that Samba service starts automatically every time your system boots, use:
sudo systemctl enable smbd
Step 4: Backup the Samba Configuration File
Before making any changes to the configuration file, it’s a good idea to create a backup. This way, if something goes wrong, you can restore the original settings.
To back up the file, run this command:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
Now you have a backup of your Samba configuration file.
Step 5: Edit the Samba Configuration File
You will need to edit the Samba configuration file to define the shared folders and settings.
Open the file in a text editor like nano:
sudo nano /etc/samba/smb.conf
You’ll see many lines in this file, but don’t worry. You’ll only need to change a few sections to get Samba working as below:
-
Set Workgroup and Server String: In the
[global]
section, configure the following basic settings[global] workgroup = WORKGROUP # Set this to match your network's workgroup (default is WORKGROUP). server string = Samba Server # Description of your server
-
Networking Settings: Ensure Samba is listening on the correct network interfaces. By default, it should listen on all interfaces. However, you can specify particular ones
interfaces = lo eth0 # Replace 'eth0' with your network interface bind interfaces only = yes
-
Set Permissions and Access Control: Decide on the security mode. For a simple setup,
user
mode is commonly used, which allows only authenticated userssecurity = user
-
Enable Samba Logging (Optional): Logging can help with troubleshooting if issues arise
log file = /var/log/samba/%m.log max log size = 50
Step 6: Create a Shared Folder
Let’s say you want to share a folder called shared. First, create the folder by running this command:
sudo mkdir /srv/samba/shared
Change the folder’s permissions so others can access it:
sudo chmod 777 /srv/samba/shared
This makes the folder accessible to everyone on the network.
Step 7: Add the Shared Folder to the Samba Configuration
Now, go back to the configuration file (/etc/samba/smb.conf
), scroll to the bottom, and add this block of text to define the shared folder:
[shared]
path = /srv/samba/shared
browsable = yes
writable = yes
guest ok = yes
read only = no
Here’s what these settings mean:
- path: The folder you’re sharing.
- browsable: This makes the folder visible to others on the network.
- writable: Allows other users to write files to this folder.
- guest ok: Allows access without a username or password.
- read only: Set to “no†so that people can write files to the folder.
Step 8: Create a Samba User
To secure your shared folder, you might want to create a Samba user. This ensures that only specific people can access the shared folder.
- First, create a system user (if you don’t already have one):
sudo adduser sambauser
- Now, create a Samba password for this user:
sudo smbpasswd -a sambauser
You will be asked to enter and confirm the password. This will create the user to the Samba database.
Step 9: Restart Samba
Whenever you make changes to the configuration file, you need to restart Samba for the changes to take effect. But before restarting it check the Samba configuration file using following command:
testparm
This will check Samba configuration file and display parameters on console. Once you see “Loaded services file OK†in output, restart Samba service using the following command.
sudo systemctl restart smbd
Step 10: Allow Samba Through the Firewall
If you have a firewall enabled, you’ll need to allow Samba traffic through the firewall. You can do this by running:
sudo ufw allow samba
This will open the necessary ports for Samba.
Step 11: Access Samba Share from Remote Computer
-
From a Windows Computer:
- Open “File Explorerâ€.
- In the address bar, type
\<your-ubuntu-ip-address>shared
and press Enter. - If you set up a user, you’ll be prompted to enter the username and password (e.g., sambauser and the password you created).
-
From Another Linux Computer:
- Open the file manager.
- Go to “Networkâ€.
- Look for your Ubuntu computer in the list.
- Open the shared folder (shared), and enter the username and password if prompted.
Step 12: Secure the Samba Share
If you don’t want everyone on your network to access the folder, you can disable guest access by setting guest ok = no
in the configuration file.
If you want to restrict access to only certain users, add this line to the share configuration:
valid users = sambauser
This will ensure that only the user sambauser can access the shared folder.
Conclusion
You have successfully installed and configured Samba on your Ubuntu system. Now, you can share files between your Ubuntu machine and other devices on your network, such as Windows and Linux computers.
With Samba, file sharing between different operating systems becomes easy and convenient! If you need more advanced features, Samba offers many more options that you can explore in its configuration file.
The post How to Install and Configure Samba on Ubuntu appeared first on TecAdmin.
Source: Read More