Samba Installation and Config

Below I’ll show you how to set up your own Samba server with CentOS 8 as the operating system and an IP address of – It’s really easy as all you need is just Samba and a few client tools (samba-common & samba-client) but it would be good just to have other clients on hand in.

# yum install samba samba-client samba-common -y

Create a directory and set permissions #

Install the required packages and let’s create a directory on the server. Create a directory called share in our root directory and set the permissions. Picking a name for your directory is entirely up to you. Once you have selected a name, assign read, write and executive permissions to the directory (ex. chmod 777). If you are using Samba as your configuration, it will control access without manual intervention on your behalf.

# mkdir /share

# chmod -R 777 /share

Configure a share

We now have all the necessary packages installed, it’s time to configure the shared directory. The configuration file is located under /etc/samba. Modify your configuration so that the content regards the text editor you use. Leave everything else as is and this should suffice for now.

# vim /etc/samba/smb.conf [myshare] comment = My share path = /share read only = No

I created a share called “myshare” and provided a path to the share, which in our case is located at “/share.” I then gave it read/write privileges with read-only set to “No.” There are many other configuration parameters that you may pass here, but this is what we need for now.

Check the Samba configuration

Samba provides a tool to check our configuration file. We can use the “testparm” command to see if there are any errors in the configuration file.

# testparm

Next, we need to create a Samba user account. To do this, you can use the ‘smbpasswd’ command. One function that it performs is connecting to shares if run as root. The smbpasswd command also lets you perform other functions, but only by running as a root user. If you execute the command ‘smbpasswd’ as a non-root user, it will change the password for your current logged in user. If you execute it using sudo, you will be able to add new Samba users.

# smbpasswd -a user New SMB password: Retype new SMB password:

The Samba service requires the ability to read the contents of the /share directory. Right now, it is not able to access this properly due to SELinux configuration restrictions. In order alleviate this issue, you need to configure SELinux so that it permits local users and groups who are members of the “sambashare” group modify files at that

# semanage fcontext -a -t samba_share_t “/share(/.*)?” # restorecon -R -v /share

To do that, we first need to enable the smb and nmb services.

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

If you’re running firewalld on your server, you’ll need to set up samba access by way of the firewall-cmd command.

After configuring the share, it is worth checking if it is visible from our machine. That’s precisely why I have installed the samba tools on my local machine beforehand, so this command might be useful:

smbclient -U <samba username we created above> -L <ip address of server>

# smbclient -U user -L Enter SAMBA\user’s password:

Let’s verify what is going on by running the following command on the server:

# smbclient -U user // Enter SAMBA\user’s password: Try “help” to get a list of possible commands. smb: \>

Wrap up

We are happy to say that we succeeded with installing and configuring the Samba file-sharing service on our Linux server. We managed to access those files locally and in the next article, we’ll set up one client from Linux and one from Windows 10.

2. Configure File Server – Anonymous Share #

a. You can create a shared folder called “shared folder”.

sudo mkdir -p /srv/samba/sharedfolder

b. ​Anyone have access and be able to store all their files securely in to a folder.

sudo chown nobody:nogroup /srv/samba/sharedfolder/

c. Edit configuration file and other settings to allow sharing.

Always make a backup of the configuration file before editing.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

The configuration file is open and the following changes need to be made:

sudo vi /etc/samba/smb.conf

Add the following at the end of the file to enable sharing –

sudo systemctl restart smbd.service nmbd.service

3. Configure File Server – Secured Share #

a. ​I want to create a shared folder called “securedfolder”.

sudo mkdir -p /srv/samba/securedfolder

b. ​You probably want to create a new user group and name it something like “selected”.

sudo addgroup selected

c. ​I think you need to modify the permissions and ownership for that folder.

sudo chown root:selected /srv/samba/securedfolder/ sudo chmod 770 /srv/samba/securedfolder/

d. To share files with other computers on your network,

​Always back up the original configuration file before editing the configuration with a text editor.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Append your changes to the end of the .conf file.

sudo vi /etc/samba/smb.conf

Add the following at the end of the file if you wish to enable sharing –

[sharedfolder] comment = secured shared folder path = /srv/samba/securedfolder Valid users = @selected guest ok = no writable = yes browsable = yes

e. Restart the smbd service

sudo systemctl restart smbd.service nmbd.service

f. ​Once Samba has restarted, use this command to check your smb.conf for any syntax errors. testparm g. Add new users

​We are going to create and add a user “Jack” to the user group “selected” with restricted shell access. sudo useradd jack -s /usr/sbin/nologin -G selected To add a password for the user –

sudo smbpasswd -a jack

h. Add existing user Jane to the group to the group “selected”.

sudo usermod jane -G selected

Conclusion #

You should be able to access and browse files from these servers from your Windows client. If you do not see your client automatically, you can try accessing it via its IP address. You can access the Ubuntu sharing in Windows by entering “\\sharedfolder” or “\\securedfolder” in the windows search field of the menu or use the network browser of the Windows file explorer to connect to the share. In the case of the secured share, the user will be required to enter the password before being able to access the shared folder. And there it is folks, a short guide to setting up samba server on Ubuntu. You can also check out the official how-to to find out more about installing and setting up Samba. ​

Leave a Reply

Your email address will not be published. Required fields are marked *