How to Set Up Samba Server and Client on CentOS: Step-by-Step Guide
This tutorial walks you through installing Samba on CentOS, creating Samba users, configuring a shared directory, editing the smb.conf file, starting services, and finally setting up a client to connect and mount the share, complete with command examples.
Samba is free software that bridges UNIX-like operating systems and Windows via the SMB/CIFS protocol, allowing file and printer sharing and even acting as a domain controller.
Server Configuration
1 Install required packages
# yum install samba samba-common -yThe samba package provides the SMB services, while samba-common supplies shared configuration files and utilities.
2 Add Samba users
Create system users that will become Samba users and add them to the centos group.
# useradd smb1 -G centos
# useradd smb2 -G centos
# useradd smb3 -G centosSet passwords for the Samba accounts.
# smbpasswd -a smb1
# smbpasswd -a smb2
# smbpasswd -a smb3List existing Samba users.
# pdbedit -L3 Create shared directory
# mkdir /samba
# chgrp centos /samba/
# chmod 2770 /samba/The directory now belongs to the centos group with appropriate permissions.
4 Edit Samba configuration
# vim /etc/samba/smb.conf
[global]
workgroup = MYGROUP # workgroup name
security = user # require user authentication
[samba]
comment = My samba share
path = /samba
browseable = yes
create mask = 0664
directory mask = 0775
write list = @centosCheck the configuration syntax.
# testparm5 Start Samba services
# systemctl start smb.service
# systemctl start nmb.service smbdmanages shared directories, files, and printers; nmbd handles workgroup and NetBIOS name resolution.
Client Configuration
1 Install client packages
# yum install samba-client samba-common -yThe client provides tools such as mount.cifs for mounting SMB shares.
2 Test connection with a Samba user
# smbclient -L //192.168.29.130 -U smb1The command lists available shares, confirming connectivity.
3 Mount the share
# mkdir /smb/
# mount -t cifs //192.168.29.130/samba /smb/ -o username=smb1,password=1234
# df -h /smbThe share is now accessible at /smb.
4 Configure automatic mount at boot
# vim /etc/fstab
//192.168.29.130/samba /smb cifs defaults,username=smb1,password=1234 0 0After saving, the share will be mounted automatically on system startup.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
