Configure Samba Server on CentOs 7
This article will be a quick guide to show you guys how to setup a network share with Samba on CentOs 7 or any other similar Linux distribution like Red Hat.
Samba share allows sharing of files between the server and various different computers on the same network.
Note: The following commands will require super user privileges.
1. Install Samba: Although Samba should come preinstalled on Centos but you can install it or check if it’s installed using the command
sudo yum install samba
2. Start services smb and nmb:
sudo service smb start && sudo service nmb start
You can now check the status of these services by typing the command
sudo service smb status
If everything is fine you will get an output like this.
3. Loading the services on login: We want these services to be loaded with the default multiuser runlevel, we want these services to be running when we login.
We first check if they are already enabled
sudo systemctl list-unit-files | grep smb
The service can be enabled using command
sudo chkconfig smb on && sudo chkconfig smb on
4. Create a directory to be shared: This will be the directory that will be shared.
sudo mkdir /home/<user_name>/<folder_name>
5. Modify the permissions of the new directory: This will ensure that the directory is readable, writable and executable.
sudo chmod –R 777 /home/<user_name>/<folder_name>
sudo chcon -R -t samba_share_t /home/<user_name>/<folder_name>
6. Set a password for your user in samba: <user_name> is the name you used to login to your CentOs server. Remember this will be the username and password that you will use to access the samba share.
sudo smbpasswd -a <user_name>
7. Edit the file “/etc/samba/smb.conf”:
sudo nano /etc/samba/smb.conf
Add the following details at the end of the file [<folder_name>] path = /home/<user_name>/<folder_name> browsable = yes guest ok = no valid users= user_name writable = yes
8. Allow samba through the firewall:
sudo firewall-cmd –permanent –zone=public –add-service=samba
sudo firewall-cmd –reload