How to Install Samba and Create File Share on Ubuntu 20.04

How to Install Samba and Create File Share on Ubuntu 20.04. In this post, we introduce Samba, its features, advantages then show you how to install Samba and create file share on Ubuntu 20.04.

First of all, Samba runs on most Unix like systems, such as Linux, Solaris, AIX, etc. It also runs on the BSD variants, including Apple’s macOS Server, as well as the macOS Client (Mac OS X 10.2 and later).

The installation procedure for Samba differs depending on which Unix or Linux version is in use by the operator. Due to the differences in technology between these operating systems, Samba is quite complex.

So, let’s start with How to Install Samba and Create File Share on Ubuntu 20.04.

What is Samba?

Image Source: udsenterprise 

Samba is an open source software that provides file and print services to SMB/CIFS clients. It is not just a simple file server but also a domain controller, a DNS server, and an Active Directory server. You can install Samba on all major operating systems like Windows, Linux, Unix, etc.

Moreover, Samba is client/server technology that implements the sharing of network resources between operating systems. This software is a reimplementation of the SMB network protocol in free software.

The name Samba comes from SMB (Server Message Block), the name of a proprietary protocol used by the Microsoft Windows network file system. Server Message Block, develop by Windows, also integrates into Windows products since the early 1990s. As of version 4, Samba supports Active Directory and Microsoft Windows NT domains.

It disperses file and printer services to Windows clients, and it integrates with Windows Server domains as the main DC or a member of the domain. Samba also transports transaction protocols for inter process communications. It works like a centralized system which really works for connecting different OSes to available resources which need to be shared.

In normal cases, when you are talking about sharing files or other documents, the process is quite complicated, especially when exchanging data among the various operating systems. But, systems in connection with the Samba server are able to easily share or share files.

The samba server on Linux has been considered one of the more powerful servers which makes it easier for other operating systems to access shared files and useful resources such as printers.

Features of Samba

  • Offers security fixed packages.
  • Unicode support.
  • Supports working as Backup Domain Controller (BDC).

Advantages of Samba

Some of the major advantages of Samba are shown below:

Offers stability and better performance

Primarily speaking, Samba is a free and open source software that provides stability and performance to Linux and Unix servers. It has years of experience and is a great option for an SMB stack, especially for production environments.

Flexible and Reliable

Then, with Samba is an application suite that helps in sharing files, printers, and other important information across the network. It also helps in providing security for shared files on Windows computers. Samba offers flexibility, reliability, scalability, ease of installation, interoperability with Windows machines, as well as many other features.

Ability to work as a cluster

Samba servers works as a cluster. This means that there is no single point of failure and it is easy to scale the system to meet the needs of an organization. You can also use SAMBA+ server for file and print services, which are commonly needed by an organization.

Supports Active Directory features

Samba is a Linux based open source SMB/CIFS client and server software package. It supports Active Directory features like multi master replication and directory services.

Now it is the main part of the article How to Install Samba and Create File Share on Ubuntu 20.04

How to Install Samba and Create File Share on Ubuntu 20.04

In this section, we show you how to install Samba and create a private and public shares on Ubuntu 20.04.

Install Samba Server

By default, the Samba server package is included in the Ubuntu default repo. You can install it using the following command:

				
					apt-get install samba samba-common-bin acl -y
				
			

After the successful installation, you start the Samba service and enable it to start at system reboot with the following command:

				
					systemctl start smbd nmbd
systemctl enable smbd nmbd
				
			

Next, verify the Samba version with the following command:

				
					smbd --version
				
			

You will get the Samba version in the following output:

				
					Version 4.13.17-Ubuntu
				
			

Create Private File Share In Samba

Image Source: Youtube

In a private share, only authenticated user can access their personal files over the network. In this section, we will show you how to create a private share in Samba.

Create a User for Samba

First, you will need to create a user for Samba. You can create it with the following command:

				
					adduser sambauser
				
			

Set a user’s password as shown below:

				
					Adding user `sambauser' ...
Adding new group `sambauser' (1000) ...
Adding new user `sambauser' (1000) with group `sambauser' ...
Creating home directory `/home/sambauser' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for sambauser
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

				
			

Next, you will also need to set a Samba password for the created user.

				
					smbpasswd -a sambauser
				
			

Set a password as shown below:

				
					New SMB password:
Retype new SMB password:
Added user sambauser.

				
			

Create a File and Directory for Private File Share

After that, you will need to create files and directories that you want to share over the network. Let’s create a directory for private share:

				
					mkdir -p /samba/private
				
			

Then, create two files inside the above directory:

				
					touch /samba/private/privatefile1.txt
touch /samba/private/privatefile2.txt
				
			

After that, assign proper permission and ownership with the following command:

				
					chmod -R 0770 /samba/private
chown -R root:sambauser /samba/private
setfacl -R -m "g:sambauser:rwx" /samba/private

				
			

Define Private File Share in Samba

Next, you will need to edit the Samba configuration file and define the private directory that you want to share:

				
					nano /etc/samba/smb.conf
				
			

Add the following lines:

				
					[Private]
comment = private share
path = /samba/private/
browseable = yes
guest ok = no
writable = yes
valid users = @sambauser

				
			

Save and close the file then validate the Samba configuration file using the following command:

				
					testparm
				
			

If everything is fine, you will get the following output:

				
					Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE
				
			

Next, restart both smbd and nmbd service to apply the changes:

				
					systemctl restart smbd nmbd
				
			

Create Public File Share In Samba

Image Source: freesvg 

A public share is a share that is available to everyone in the network. Any user in the network accesses the public share without providing a username and password. In this section, we show you how to create a public share in Samba.

Create a File and Directory for Public Share

First, create a files and directory for public share using the following command:

				
					mkdir -p /samba/public
touch /samba/public/publicfile1.txt
touch /samba/public/publicfile2.txt
				
			

Next, assign proper permission and ownership to the public share the following command:

				
					chmod -R 0777 /samba/public
				
			

Define Public File Share in Samba

Then, please edit the Samba configuration file and define your public share. You can edit it with the following command:

				
					nano /etc/samba/smb.conf
				
			

Add the following configuration:

				
					[Public]
comment = public share
path = /samba/public/
browseable = yes
writable = yes
guest ok = yes
				
			

Save and close the file when you are finished. Then, validate the Samba configuration file using the following command:

				
					testparm
				
			

Finally, restart the smbd and nmbd service to apply the configuration.

				
					systemctl restart smbd nmbd
				
			

Access Samba File Share

At this point, both public and private shares is created on the Samba server. Now, we will show you how to access both shares from the client machine.

Access Private File Share

First, you will need to install the Samba client package on the remote machine. You install it with the following command:

				
					apt-get install smbclient cifs-utils -y
				
			

After the installation, open your command line interface and access the Samba private share using the following command:

				
					smbclient //samba-ip-address/private -U sambauser
				
			

You will be asked to provide sambauser’s password to access the share as shown below:

				
					Enter WORKGROUP\sambauser's password:
				
			

Provide your password and press the Enter key. Once you are connected to the Samba, you will get the following shell:

				
					Try "help" to get a list of possible commands.
smb: \>
				
			

To see your private files from Samba share, run the following command:

				
					smb: \> ls
				
			

You should see your files in the following output:

				
					privatefile1.txt N 0 Thu Dec 1 07:37:41 2022
privatefile2.txt N 0 Thu Dec 1 07:37:46 2022

51538400 blocks of size 1024. 47721572 blocks available

				
			

Next, exit from the Samba console using the following command:

				
					smb: \> exit
				
			

Access Public File Share

To access the Samba public share, run the following command:

				
					smbclient //samba-ip-address/public
				
			

You will be asked for password to access the public share:

				
					Enter WORKGROUP\root's password:
				
			

Just press the Enter key without providing any password. You should see the Samba shell in the following output:

				
					Try "help" to get a list of possible commands.
smb: \>

				
			

To see your public share, run the following command:

				
					smb: \> ls
				
			

You should see both files in the following output:

				
					publicfile1.txt N 0 Thu Dec 1 07:39:36 2022
publicfile2.txt N 0 Thu Dec 1 07:39:43 2022

51538400 blocks of size 1024. 47721572 blocks available

				
			

Mount Private Share

First, you will need to create a directory to mount the private Samba share to your local machine:

				
					mkdir /mnt/private
				
			

Next, run the following command to mount a private share to the /mnt/private directory:

				
					mount -t cifs -o username=sambauser //samba-ip-address/private /mnt/private
				
			

You will be asked to provide a password to mount a private share:

				
					Password for sambauser@//208.117.84.208/private: ******
				
			

Next, verify your mounted share using the following command:

				
					df -h
				
			

You should see the mounted share in the following output:

				
					//samba-ip-address/private 50G 3.7G 46G 8% /mnt/private
				
			

To verify your files inside the /mnt/private directory, run the following command:

				
					ls -l /mnt/private
				
			

You should see both files in the following output:

				
					-rwxr-xr-x 1 root root 0 Dec 1 07:37 privatefile1.txt
-rwxr-xr-x 1 root root 0 Dec 1 07:37 privatefile2.txt

				
			

Thank you for reading How to Install Samba and Create File Share on Ubuntu 20.04. We will conclude this article now. 

How to Install Samba and Create File Share on Ubuntu 20.04 Conclusion

In this guide, we have explained how to install Samba and create a public and private file shares on Ubuntu 20.04. Samba is a program that allows end users to access and use printers, files, and other frequently shared resources over the Internet.

It uses the Server Message Block (SMB) protocol to facilitate the sharing of files, folders, and the distribution of printers across a network. Without having to install the NFS service on the Window system, Samba provides complete networking functionality with Windows.

In addition, Unix based systems may use Samba to facilitate SMB access to file and printing services. For many years, SMB has been used mostly for connecting Windows computers, though most other systems, such as Linux and macOS. Windows clients utilize the files and printer resources on a server by passing the server message block through a NetBIOS session.

Take a look at our Ubuntu content by navigating to our blog here and also for more printing content click here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x