Atlantic.Net Blog

How to Create Samba Share on Ubuntu 20.04

Hitesh Jethva
by Atlantic.Net (345 posts) under Tutorials, VPS Hosting
0 Comments

Samba, also known as “Server Message Block,” is a Common Internet File System protocol used for sharing files, directories, and print services across a network on Linux. It allows you to grant read, write, and anonymous access permissions on a shared directory. It is extremely useful for those who use both Windows and Linux systems on their network.

In this post, we will explain how to install and use Samba to share files and directories on Ubuntu 20.04.

Prerequisites

  • A fresh Ubuntu 20.04 server on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Samba Server

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

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

Once installed, start the Samba services and enable them to start at system reboot:

systemctl start smbd nmbd
systemctl enable smbd nmbd

You can check the installed version of Samba with the following command:

smbd --version

Output:

Version 4.11.6-Ubuntu

Step 3 – Create a Private Share with Samba

In this section, we will show you how to create a private share using Samba so that only authenticated users can access the share.

To do so, edit the Samba main configuration file:

nano /etc/samba/smb.conf

Next, add the following lines at the end of the file:

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

Save and close the file, then create a new user with the following command:

adduser user1

You should see the following output:

Adding user `user1' ...
Adding new group `user1' (1000) ...
Adding new user `user1' (1000) with group `user1' ...
Creating home directory `/home/user1' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for user1
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, set a Samba password with the following command:

smbpasswd -a user1

You should see the following output:

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

Next, create a Samba group with the following command:

groupadd samba

Next, add user1 to the samba group:

gpasswd -a user1 samba

Next, create a shared folder that you have specified in the smb.conf file:

mkdir -p /data/private
touch /data/private/file1

Next, provide read and write permissions to the Samba share:

setfacl -R -m "g:samba:rwx" /data/private

Next, check the Samba configuration file for any errors with the following command:

testparm

Next, restart the Samba service to apply the changes:

systemctl restart smbd nmbd

Step 4 – Create a Public Share with Samba

In this section, we will show you how to create a public share with Samba so everyone can access the public share without providing a username and password.

To create a public share, edit the Samba main configuration file:

nano /etc/samba/smb.conf

Add the following lines at the end of the file:

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

Save and close the file, then create a public directory:

mkdir -p /data/public/
touch /data/public/file2

Next, set proper permissions on the public directory:

setfacl -R -m "u:nobody:rwx" /data/public

Next, restart the Samba service to apply the changes:

systemctl restart smbd nmbd

Step 5 – Access Samba Share from Linux

In order to access the Samba share, you will need to install the Samba client on the Linux system. You can install it using the following command:

apt-get install smbclient cifs-utils -y

Next, run the following command to access the private share from the Samba server:

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

You will be asked to provide a password for user1:

Enter WORKGROUP\user1's password: 
Try "help" to get a list of possible commands.

Once you are connected, run the following command to list Samba share:

smb: \> list
0:	server=69.87.221.84, share=private

Next, list all the files in the private share directory:

smb: \> ls

You should see the following output:

  .                                   D        0  Sun Jun 27 08:17:58 2021
  ..                                  D        0  Sun Jun 27 08:18:13 2021
  file1                               N        0  Sun Jun 27 08:17:58 2021

		51538400 blocks of size 1024. 47348972 blocks available

Next, exit from the Samba shell with the following command:

smb: \> exit

If you want to connect to the Public share, run the following command:

smbclient //samba-ip-address/public

Just press Enter without providing any password:

Enter WORKGROUP\root's password: 

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

Next, run the following command to list all files in the Public share:

smb: \> ls

Output:

  .                                   D        0  Sun Jun 27 08:18:17 2021
  ..                                  D        0  Sun Jun 27 08:18:13 2021
  file2                               N        0  Sun Jun 27 08:18:17 2021

		51538400 blocks of size 1024. 47348972 blocks available

Step 6 – Mount Samba Share on Linux

Samba also allows you to mount a shared directory to the client system so you can access and use it.

First, create a directory on the client system where you want to mount the Samba share:

mkdir /mount

Next, run the following command to mount the Private share directory to the client system:

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

You will be asked to provide a password of user1 to mount the directory:

Password for [email protected]//69.87.221.84/private:  ********* 

Next, verify the mounted directory with the following command:

df -h

You should see your Private shared directory mounted on the /mount directory:

Filesystem              Size  Used Avail Use% Mounted on
udev                    981M     0  981M   0% /dev
tmpfs                   199M  2.2M  197M   2% /run
/dev/sda1                50G  1.9G   46G   4% /
tmpfs                   994M     0  994M   0% /dev/shm
tmpfs                   5.0M     0  5.0M   0% /run/lock
tmpfs                   994M     0  994M   0% /sys/fs/cgroup
tmpfs                   199M     0  199M   0% /run/user/0
//69.87.221.84/private   50G  4.0G   46G   9% /mount

Now, access the Samba share locally using the following command:

ls /mount/

You should see the following output:

file1

Conclusion

In the above guide, you learned how to install Samba and use it to share files and directories between Linux systems. Give it a try on VPS hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Python 3.10 on Rocky Linux 8
How to Install TaskBoard on Rocky Linux 8
How to Set Up Pritunl VPN Server on Rocky Linux 8
How to Install Teampass Password Manager on Rocky Linux 8
How to Install and Configure RabbitMQ Server on Rocky Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources