A file server is a crucial component in today’s data-driven world, allowing users to store, share, and access files within a network. Oracle Linux is a popular choice for file servers due to its robustness, security, and scalability. In this article, we will walk you through the process of how to build a file server on Oracle Linux.
Prerequisites
Before we begin, ensure that you have the following:
- An Oracle Linux system 7 or 8 installed and updated.
- A Root user account or with sudo privileges.
- A basic understanding of how to disable root login, enable 2FA, and use SSH keys for secure remote access.
How to Build a File Server on Oracle Linux
Install the Required Packages
We will use the Samba suite to set up our file server. Install the necessary packages by running the following command:
sudo yum install -y samba samba-client samba-common
Configure Samba on Oracle Linux
Next, create a backup of the original Samba configuration file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Open the Samba configuration file using a text editor like Vim:
sudo vim /etc/samba/smb.conf
Edit the file by adding the following lines:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = oraclelinux
security = user
map to guest = bad user
dns proxy = no
Create a new share by adding the following lines at the end of the file. Replace /path/to/share
with the actual path of the directory you want to share.
[MyShare]
path = /path/to/share
browsable =yes
writable = yes
guest ok = yes
read only = no
Save and exit the file.
Create a Shared Directory in Linux Server
Create a new directory to share with others:
sudo mkdir -p /path/to/share
Set the appropriate permissions for the shared directory:
sudo chown -R nobody:nobody /path/to/share
sudo chmod -R 0755 /path/to/share
Add Samba User and Set Password
Add a new Samba user and set a password for the user:
sudo smbpasswd -a username
Replace username
with your desired username. You will be prompted to enter a password for the user.
Start and Enable Samba Services
Start the Samba services and enable them to run at startup:
sudo systemctl start smb.service
sudo systemctl start nmb.service
sudo systemctl enable smb.service
sudo systemctl enable nmb.service
Configure Firewall
To allow Samba traffic through the firewall, run the following commands:
sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload
Test the File Server
To test the file server, run the following command:
smbclient -L localhost -U%
You should see the shared directory listed under “Sharename.”
From a Windows client, open File Explorer and enter the following in the address bar:
\\oraclelinux\MyShare
Replace oraclelinux
with the hostname or IP address of your Oracle Linux server, and MyShare
with the name of the share you created in the smb.conf
file.
From a Linux client, you can mount the shared directory with the following command:
sudo mount -t cifs //oraclelinux/MyShare /mnt -o username=username,password=password
Replace oraclelinux
with the hostname or IP address of your Oracle Linux server, MyShare
with the name of the share you created in the smb.conf
file, and username
and password
with the appropriate Samba username and password.
Secure the File Server
To enhance the security of your file server, consider the following best practices:
- Install Fail2Ban to protect your server from brute-force attacks.
- Configure a firewall to limit incoming and outgoing traffic.
- Enable SSL/TLS encryption for secure communication between the server and clients.
- Regularly update your server with security patches.
Conclusion
You have successfully set up a file server on Oracle Linux using Samba. Your users can now store, share, and access files within the network. As your needs grow, you can easily add additional storage using RAID configurations or even set up an OpenVPN server for remote access to your file server.
Remember to follow security best practices to protect your server and data from potential threats.