Atlantic.Net Blog

How to Create a Samba Share on Oracle Linux 8

Samba is a free and open-source Server Message Block protocol that provides file and print services between clients across various operating systems. Samba allows you to share files and directories between Linux and Windows operating systems. It can also integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member.

In this post, we will show you how to install the Samba server and create a private and public share on Oracle Linux 8.

Step 1 – Install Samba Server

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

dnf update -y
dnf install samba samba-common samba-client -y

Once the Samba packages are installed, start and enable the smb and nmb services with the following command:

systemctl start smb
systemctl enable smb
systemctl start nmb
systemctl enable nmb

Step 2 – Create a Public Share

In this section, we will show you how to create a public share on Samba so that everyone can access it without authentication.

First, create a directory for the public share and provide the necessary permissions:

mkdir -p /data/public
touch /data/public/public.txt
chmod -R 755 /data/public
chown -R nobody:nobody /data/public

Next, backup the default Samba configuration file and create a new one with the following command:

mv /etc/samba/smb.conf  /etc/samba/smb.conf.bak
nano /etc/samba/smb.conf

Add the following configuration:

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = Oracle Linux 8
security = user
map to guest = bad user
dns proxy = no

[Public]
path = /data/public
writable = yes
guest ok = yes
read only = no

Save and close the file, then restart the smb and nmb services to apply the changes:

systemctl restart smb
systemctl restart nmb

Step 3 – Create a Private Share

In this section, we will show you how to create a private share on Samba so that the user needs to authenticate to Samba to access the share.

First, create a user and group with the following command

groupadd private
useradd -g private private

Next, create a directory for the private share and provides the necessary permissions:

mkdir -p /data/private
touch /data/private/private.txt
chmod -R 755 /data/private
chown -R root:private /data/private

Next, set the password for the private user with the following command:

smbpasswd -a private

Set your password as shown below:

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

Next, edit the Samba configuration file with the following command:

nano /etc/samba/smb.conf

Add the following configurations at the end of the file:

[Private]
path = /data/private
valid users = @private
guest ok = no
writable = yes
browsable = yes

Save and close the file, then restart the smb and nmb service to apply the changes:

systemctl restart smb
systemctl restart nmb

Step 4 – Install Samba Client and Access the Samba Share

Next, go to the remote machine and install the Samba client with the following command:

dnf install samba-client cifs-utils -y

Next, run the following command to access the private share:

smbclient //server-IP/private -U private

You will be asked to provide your password to access the private share:

Password for [WORKGROUP\private]:

Once you are authenticated, you will get the following output:

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

Next, run the following command to list all files inside the private share:

smb: \> ls

You will get the following output:

  .                                   D        0  Fri Sep 16 03:06:25 2022
  ..                                  D        0  Fri Sep 16 03:06:19 2022
  private.txt                         N        0  Fri Sep 16 03:06:25 2022

		83873792 blocks of size 1024. 75576444 blocks available

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

smb: \> exit

To access the public share, run the following command:

smbclient //server-IP/public

You should see the password prompt:

Password for [WORKGROUP\root]:

Just press the Enter key to connect to the Samba shell:

Try "help" to get a list of possible commands.

smb: \>

Next, list all files inside the public share with the following command:

smb: \> ls

You should see the following output:

  .                                   D        0  Fri Sep 16 03:04:35 2022
  ..                                  D        0  Fri Sep 16 03:06:19 2022
  public.txt                          N        0  Fri Sep 16 03:04:35 2022

		83873792 blocks of size 1024. 75576424 blocks available

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

smb: \> exit

Conclusion

In this post, we explained how to install the Samba server and create a private and public share on Oracle Linux 8. You can now easily share files and directories between multiple machines easily. Try it on VPS hosting from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a 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