Samba is a service or you can say a protocol that allows you to share and access data between Linux and Windows systems. It is the basic protocol for sharing files and printers between Windows and Linux/Unix systems. In this tutorial, we are going to configure Samba in Ubuntu 17.04. However, the same steps can be used for earlier versions of Ubuntu such as Ubuntu 16.04. For other Linux variants, you may need to adjust some commands depending on the Linux variant you use. We will configure the samba server in Ubuntu as per the following requirements:
- Samba share name: /home/sales
- Permission: read and write
- Allowed users: smbuser1
- Network: 192.168.153.0/24
Recommended: Configure DNS in Ubuntu Linux 17.04
Steps To Configure Samba In Ubuntu Linux
In order to configure samba in Ubuntu Linux, you need to perform the following steps:
1. Installing Samba Packages
Use the following command to install samba packages in Ubuntu Linux
sudo apt install samba –y
2. Creating a Samba Share and Setting the Permissions
Use the following commands to create a samba share and set the permissions
sudo mkdir –p /home/sales sudo chmod 770 /home/sales
Creating Group and Adding Group With Samba Share
Use the following command to create a group and change the group for samba share
sudo groupadd sales sudo chgrp sales /home/sales
3. Modifying the /etc/samba/smb.conf file.
Use your favorite file editor and make the following changes in the samba configuration file
#In the Networking section, make the following changes interfaces 127.0.0.0/8 eth0 192.168.153.0/24 bind interfaces only = yes #In the same file, scroll-down to the end and add the following settings: [sales] path = /home/sales writable = yes create mode = 0770 directory mode = 0770 guest ok = yes valid users = @sales
Save the file and use the testparm command to check the syntax of smb.conf file.
4. Adding and Enabling Samba User
Now, create a Samba user named smbuser1 and add it to the sales group.
sudo useradd smbuser1 sudo smbpasswd -d smbuser1 sudo usermod –G sales smbuser1
To enable samba user, use the following command.
sudo smbpasswd –e smbuser1
5. Enabling and Restarting Samba Service
Use the following commands to enable and restart the samba service in Ubuntu Linux
sudo systemctl restart smbd sudo systemctl status smbd
We assume that you have allowed the appropriate ports in the firewall. If required, for the testing purpose, you can disable the firewall and SELinux. However, in the production network, you must have to set the appropriate firewall rules and SELinux settings.
Now, you are ready to access samba share. Move on to Windows system and type \\samba-server-ip\sambashare in the Run dialog box. Alternatively, you can also mount the samba share as a network drive as shown in the following figure. Use the smbuser1 credential to access the samba share in Windows system.
Now, you should be able to access the samba shared data from the Windows system. If you get stuck anywhere, please write to us in the comment box. Please also share and like the tutorial if it helped you.
- Also read: Configure NFS in Ubuntu Linux