How to set up a file server on CentOS?

To set up a file server on CentOS, you can use either the Samba or NFS service. Here are the basic steps:

  1. Install either Samba or NFS service.
  1. Install the Samba service: Use the following command to install the Samba service.
sudo yum install samba samba-client
  1. Install NFS service: Run the following command to install NFS service:
sudo yum install nfs-utils
  1. Set up shared folder.
  1. To set up the Samba service, open the Samba configuration file located at /etc/samba/smb.conf and add the following content at the end of the file:
[shared_folder]
   path = /path/to/shared_folder
   writable = yes
   guest ok = yes
   browseable = yes
  1. To configure the NFS service, edit the NFS configuration file /etc/exports and add the following content at the end of the file.
/path/to/shared_folder <client_ip>(rw,sync,no_root_squash)
  1. Start and activate the service:
  1. Start and enable the Samba service.
sudo systemctl start smb
sudo systemctl enable smb
  1. Start and enable NFS service.
sudo systemctl start nfs
sudo systemctl enable nfs
  1. Set up firewall rules:

If you have enabled the firewall on your CentOS server, you will need to allow the relevant ports for Samba or NFS services to pass through the firewall. For example, to allow the relevant ports for Samba services, you can run the following command:

sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload
  1. Mount shared folder:
  1. You can mount a shared folder by accessing smb://server_ip/shared_folder on either a Windows or Linux client for Samba services.
  2. To mount a shared folder on a Linux client for NFS service, you can use the following command.
sudo mount -t nfs server_ip:/path/to/shared_folder /mnt/nfs

In this way, you can successfully set up a file server on CentOS and share files with other devices.

bannerAds