Install all necessary Samba packages
Logon to your CentOS with the admin account, default is: username=root, password=password
Next, to install the necessary packages run the following command:
yum -y install samba samba-client samba-common
Creating the Samba Configuration File
Editing the configuration file can be done using any text editor (vi, vim, nano, etc).
To use vi, enter i to make changes to the text. When done, hit the Esc key, and then enter :wq to save and exit.
Run the following command to edit the necessary configuration file:
vi /etc/samba/smb.conf
Once in the file, you’ll need to change the [global] section to the following:
[global]
workgroup = WORKGROUP
security = user
map to guest = bad user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
Password-less Access to Share
Below the [global] section, add your share definition in the same format. The first example is a share called “Storage” that will allow everyone to have access to the /mnt/data directory :
[Storage]
path = /mnt/data
browsable = yes
writeable = yes
force user = nobody
force group = nobody
read only = no
guest ok = yes
Once you exit the text editor, you’ll need to run the following command:
chown -R nobody:nobody /mnt/data
The above settings will not prompt anybody for a username or password when connecting to the share.
*For your share, change the share name to whatever you want to name it, and change the path from /mnt/data to the directory you want to share.
Password Protected Shares
Below is an example of a share that prompts users for a username and password before given access:
[Storage]
path = /mnt/data
valid users = @securedgroup
guest ok = no
writeable = yes
browsable = yes
For this method to work, you will now need to create a group, in our example it is called ‘securegroup’, and then create all the users you want to give access to the share. This can be done with the following commands:
groupadd securegroup
useradd username –G securegroup
smbpasswd –a username
Final Steps
You must enable to smb service and update firewall settings by running the following commands:
systemctl enable smb
systemctl restart smb
firewall-cmd –add-service=samba –permanent
firewall-cmd –reload
Accessing the Samba Share
To access the Samba share on a Windows client, go to “Computer” and then “Map Network Drive”
Enter the IP address and the Share name in the format shown below:
\\192.168.16.4\Storage
*If the share is password protected, then make sure to check the “Connect using different credentials” box*