Saturday, November 9, 2024
HomeTutorialsHow To Install Samba File Sharing Server on Linux System

How To Install Samba File Sharing Server on Linux System

The Samba file-sharing server of the SMB, in short, is an open-source file-sharing server specially designed for Linux systems. It allows sharing files among client PCs from a hosted server. It’s not a conventional FTP server type server, and it does not require hosted files for the client users. You can use the Samba file-sharing server on Linux to access the Windows files over a network. Samba can be used for both personal and business usage. In Samba, users get both read and write permission for file accessing. They can change, revise, edit files over the server, and the changes go live immediately. In a word, using the Samba for sharing files with clients with access permission is hassle-free and strong in Linux.

Samba File Sharing Server on Linux


The Samba file-sharing server was initially released in 1992 as a distributed network file system. In Linux, using the Samba file sharing service is secure and remotely accessible. It is written in the C and Python programming language and is licensed under the GNU privacy license. In Linux, the Samba file share server acts as an easy access door over a network that can go live publically.

You can use the Samba server on a Linux machine on your local area network system. If also allows sharing files from Windows and Mac. For setting up the Samba file server, you will need to know the basic knowledge of Linux file servers. In this post, we will see how to install and configure the Samba file-sharing server on Linux.

1. Samba File Sharing Server On Ubuntu


The Samba file sharing server is officially available on the Linux repository. In Ubuntu and other Debian distributions, you can run the following commands given below to install the Samba file-sharing server on Ubuntu.

sudo apt update
sudo apt install samba

install Samba on Ubuntu

Once the Samba installation ends up, you may now check the Samba file location to make sure that it has been installed correctly or not.

whereis samba

whereis samba

After installing the Samba file sharing server on your machine, you can now make a new directory on your filesystem for the Samba file sharing server to host the files that you want to share over your local network.

sudo mkdir /home/ubuntupit/sambashare/

After creating the folder, we will now edit the Samba file-sharing server configuration script to allocate the Samba path. You can execute the following command given below to open the Samba configuration script with editing access.

sudo nano /etc/samba/smb.conf

Once the script opens, please copy and paste the following script lines given below. You may need to edit the script codes and put in your own credentials.

sudo nano edit samba config

[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes

After editing the configuration script, we will now restart the Samba file-sharing server on our Linux machine.

sudo service smbd restart

If you can’t find your Samba file sharing server on a local area network, ensure that the firewall is not protecting it on your network.

sudo ufw allow samba

Now, you may also add a user for the Samba file sharing server on your machine.

sudo smbpasswd -a username

2. Install Samba On Red Hat Linux


Installing the Samba file sharing server on a Fedora workstation or Red Hat Linux-based distributions is a bit different, and the configuration scripts are also not the same as Ubuntu. But no worries, here will cover installing and configuring the Samba file sharing server on YUM-based systems. If your Fedora workstation is upgraded up to the latest, the following YUM commands will also be executable on Fedora.

Step 1: Install Samba Client Tool


First, update your system repository to make sure that the YUM won’t face issues while pulling the Samba client from the official repository.

sudo yum update

Now, execute the following YUM command with root access to install the Samba server client tool on your Linux system.

sudo yum install samba samba-common samba-client

The installation would not take a long time; as soon as it finishes, we will create a backup of the Samba configuration file so that we can restore it if we do something wrong with the configuration file.

sudo mv /etc/samba/smb.comf /etc/samba/smb.conf.bk

Step 2: Configure Samba File Sharing Server On Linux


We will now make a new directory for the Samba file sharing server on our Linux directory. Now, run the following change mode commands supplied below to access full editing permission for the directory.

sudo mkdir -p /srv/samba/repository
sudo chmod -R 755 /srv/samba/repository
sudo chown -R nobody:nobody /srv/samba/repository
sudo chcon -t samba_share_t /srv/samba/repository

You may now run the following Nano command to edit the Samba configuration file.

sudo nano /etc/samba/smb.conf

When the script opens up, please input the following configuration lines inside the script, then save and close the file. Please note, you might need to edit the script according to your own server’s data and parameters.

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

[Public]
path = /srv/samba/repository
browsable =yes
writable = yes
guest ok = yes
read only = no

Now run the following command to test the Samba server on the machine.

sudo testparm

It would also help to find your server on the local area network if you allow the firewall tool to make your Samba server accessible. The firewall requires to be restarted after making any changes.

sudo firewall-cmd --add-service=samba --zone=public --parmanent
sudo firewall-cmd --reload

Till now, we have seen steps of installing and configuring the Samba server on a Fedora/Red Hat Linux system. We will now see commands to start and enable the Server Message Block protocol and the Samba server for making it accessible from Windows.

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

After enabling and starting the SMB and NMB on your Linux system, you may now check the status by running the following system control commands given below.

sudo systemctl status smb
sudo systemctl status nmb

3. Install Samba on Fedora


Fedora has its own DNF commands for installing the Samba server on the system. You can run the following commands given below to install the Samba server on the Fedora workstation.

sudo dnf install samba

sudo dnf install Samba File Sharing Server On Linux

When the installation ends up, you may now enable it on the system with the system control command given below.

sudo systemctl enable smb --now

Now, make sure that your system’s firewall daemon is allowing the Samba server on your LAN.

firewall-cmd --get-active-zones
sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-service=samba
sudo firewall-cmd --reload

After installing and enabling Samba on the system, we will now make a new user for the Samba file-sharing server on the Fedora workstation.

sudo smbpasswd -a ubuntupit

Then, we will need to share out the folder that we want to share via the server. Please perform the following commands given below to allocate a folder and share it on the local area network.

mkdir /home/ubuntupit/share
sudo semanage fcontext --add --type "samba_share_t" ~/share
sudo restorecon -R ~/share

Once you’ve installed and selected the directory, now you might need to edit the Samba file server configuration script on your Linux machine. Please run the following Nano command given below to edit the Samba configuration script with Nano.

sudo nano /etc/samba/smb.conf

Once the script file opens, input the following lines in your script, then save and exit the file.

[share]
comment = My Share
path = /home/jane/share
writeable = yes
browseable = yes
public = yes
create mask = 0644
directory mask = 0755
write list = user

Finally, reload the Samba server and the firewall daemon on your Linux machine to see the impact.

sudo systemctl restart smb

Reload the Firewall daemon on Fedora.

# firewall-cmd --add-service=samba --permanent
# firewall-cmd --reload

Final Words


Having a file-sharing server over the local area network is always good for boosting work performance. If you have a workstation where you need to work on both Linux and Windows systems, choosing the Samba file server is always an excellent decision. In the entire post, I’ve described the methods of installing the Samba file-sharing server on a Linux machine.

I hope this post has been helpful to you. Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

You May Like It!

Trending Now