How to setup Samba Server and client on AlmaLinux

File servers often need to accommodate a variety of different client systems. Running Samba allows Windows systems to connect and access files, as well as other Linux systems and MacOS. An alternative solution would be to run an FTP/SFTP server, which can also support the connections from many systems.

In this guide, we’ll go over the instructions to setup a Samba server on AlmaLinux. This is a great way to prepare your file server after installing AlmaLinux or migrating from CentOS to AlmaLinux. We’ll also see how to connect to the file server from other AlmaLinux client computers.

In this tutorial you will learn:

  • How to install Samba on AlmaLinux
  • How to allow Samba through firewalld
  • How to create a Samba user
  • How to configure Samba to share a directory
  • How to allow Samba through SELinux
  • How to connect to Samba server from AlmaLinux client
Setting up a Samba share on AlmaLinux

Setting up a Samba share on AlmaLinux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System AlmaLinux
Software Samba
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Samba

The first step is to install Samba on AlmaLinux, in case it’s not already on the system. Use the following command to install the necessary Samba packages via the dnf package manager.

$ sudo dnf install samba samba-client

Once the packages are installed, we have to start and enable the smb and the nmb daemons at boot. The first is the daemon which takes care of performing the actual transfers and the sharing operations, while the second performs the NetBIOS name resolutions, allowing the resources to appear when browsing the network on Windows. We can now enable and start both systemd services with just one command:

$ sudo systemctl enable --now {smb,nmb}

Allow Samba through firewall

AlmaLinux comes with firewalld enabled by default, and it will block other connections from other computers that are trying to access our Samba service. We can allow the proper ports through firewalld by running the following commands. Be sure to add --zone option to your command if necessary for your configuration.

$ sudo firewall-cmd --permanent --add-service=samba
$ sudo firewall-cmd --reload


Create a Samba user

It’s possible to setup a Samba share that doesn’t require account credentials to connect to, but it’s not practical in most situations because of the obvious security concern. Instead, it’s better to create user accounts for the people that will be connecting to the Samba share.

Each Samba user will need a normal user account on the AlmaLinux system. This doesn’t mean that you have to give them a home directory, or shell, or anything like that, but they’ll still need a user account. If they already have a user account on the system, then that will suffice. Otherwise, we’ll need to create a brand new account. Use the following command to make a new user account for our Samba share.

$ sudo adduser -M sambauser -s /sbin/nologin

The -M option passed to the command is the short form for --no-create-home, which is quite self-explanatory. And the -s option allows us to specify a shell, in this case an invalid one on purpose: /sbin/nologin. There’s no need to set a password for this user account, only a password for the Samba service.

Create a Samba password for the newly created user with the following command:

$ sudo smbpasswd -a sambauser
New SMB password:
Retype new SMB password:
Added user sambauser.

Configure Samba to share a directory

Now that we have Samba running and a new user created, let’s configure a directory that we wish to share through Samba.

For our example, we’ll make our shared directory at /mnt/shared.

$ sudo mkdir -p /mnt/shared
$ sudo chmod 777 /mnt/shared

Now let’s edit the Samba configuration file to tell the service about this new directory that we’d like to share. Use nano or your favorite text editor to open the following configuration file.

$ sudo nano /etc/samba/smb.conf


Go all the way to the bottom of this file, and paste the following lines.

[linuxconfig]
        path = /mnt/shared
        guest ok = no
		read only = no

Note that in this example we have named our share linuxconfig by putting it inside of brackets. You’ll need to know this name when mounting the share on a remote server.

Save your changes to the file and exit it. Then, restart the Samba service for the new changes to take effect.

$ sudo systemctl restart {smb,nmb}

Allow Samba through SELinux

SELinux is enabled by default in AlmaLinux. We’ll need to assign the appropriate context to our shared directory and files by using the following command. This will allow Samba to function while still keeping SELinux in the recommened enforcing mode.

$ sudo chcon -R -t samba_share_t /mnt/shared

Connecting to Samba server from AlmaLinux client

We now have a fully functional Samba server, with a dedicated Samba user and a shared directory. Other systems should be able to connect to this directory in order to upload or download files from the Samba server. This section will show how to connect to the Samba server from another AlmaLinux (client) system.

On the client system, we need to create an empty directory which we can use as a mount point for the remote Samba share.

$ sudo mkdir -p /mnt/fileserver

Next, use the mount command to mount the remote Samba share to the folder we’ve just created. You can use either the hostname of the remote machine or the IP address.

$ sudo mount -t cifs -o username=sambauser //192.168.1.10/linuxconfig /mnt/fileserver

After entering your password, the Samba share will now be mounted.

Alternatively, you can access the Samba share from GNOME’s file manager by entering the following syntax. Replace the IP address as necessary.

smb://127.0.0.1/linuxconfig/


Enter the path to the Samba share

Enter the path to the Samba share

After logging in, the Samba share will be mounted on the left side of GNOME’s file manager.

The Samba share has been mounted

The Samba share has been mounted

Closing Thoughts

In this tutorial, we learned how to install Samba on AlmaLinux. We also saw how to create a Samba share, a Samba user, and configure the firewall and SELinux to permit Samba. Then, we went over the steps to connect to our Samba server from a client machine. Using this guide should allow you to create a file server that can host connections from various operating systems.