Samba is a free and open-source software suite that provides file and print services between Windows and Unix-like operating systems. It allows computers running different operating systems to share files and printers over a local network. Samba is compatible with the Server Message Block (SMB) protocol, also known as the Common Internet File System (CIFS), which is the standard protocol for sharing files, printers, and various network resources in Windows-based environments.
Samba enables interoperability between Windows and Unix-like systems by implementing the SMB/CIFS protocol. It allows Windows clients to access files and printers shared by a Samba server, and it also allows Unix-like systems to share files and printers with Windows clients. This makes it possible to create mixed Windows and Unix-like network environments, where users can seamlessly access shared resources regardless of the underlying operating system.
In this step-by-step tutorial, we will install Samba on a remote Ubuntu server and demonstrate the Samba file sharing between a Windows server and the Ubuntu server on the same network.
Open a terminal or SSH into your Ubuntu 20.04 server and using the following command the switch to the root user so you have the permission for later operations. Then, input password as prompted.
$ sudo -i
Next, update the package repositories to ensure you have the latest package information.
$ apt update
Once the package repositories are updated, you can install Samba server by running the following command:
$ apt install samba
And type y to confirm the installation.
After the installation, you can verify if the Samba is successfully installed by running the command below. You should get the output as the arrow indicates in the following screenshot.
$ whereis samba
Now, we need to create a directory for the Samba file sharing. Use the command below to create one.
$ mkdir /home/"username"/sambashare/
In this case, we are create a directory under the /home/administrator and name the directory as "sambashare."
Then, we need to write the Samba file sharing directory into the configuration file of Samba, which is /etc/samba/smb.conf. You can use your preferred editor to modify the configuration file. Here, we will use the nano editor.
$ nano /etc/samba/smb.conf
Add the following lines to the bottom of the file.
$ [sambashare] comment = Samba on Ubuntu path = /home/administrator/sambashare read only = no browsable = yes
After the editing, press Ctrl and O on your keyboard to save the changes and then, press Ctrl and X to exit from the nano text editor.
Next, we need to restart the Samba service so the the changes we made can take effect. Run the following command.
$ service smbd restart
If you have enabled firewall on your Ubuntu server, you should also update the firewall rules to allow Samba traffic by using the following command.
$ ufw allow samba
The username used must belong to a system account. However, as Samba doesn’t use the original password of the system accounts, we need to set up a new password for the account for file sharing. In this case, we will use the administrator user. You should replace the "username" with your actual username.
$ smbpasswd -a "username"
In your Windows system, go to This PC > Computer > Map network drive > Map network drive.
In the pop-up window, input the file path as \\ip-address\sambashare. Use the IP address of your linux Samba server. Then, check the option of Connect using different credentials and click Finish. Upon the click, a new Window will pop up to prompt you to enter the user account and password to connect to the server. Lastly, click OK to connect to it.
Once your've successfully connected to the Linux Samba server, you should be able to share files between Windows and Linux smoothly.