Step‑by‑Step Guide to Installing and Configuring Samba on Linux
This article walks you through installing Samba on a Linux server, configuring shared directories with custom permissions, verifying client access, restricting mounts to specific users, persisting mounts via /etc/fstab, and creating department‑specific shares, all with concrete command examples.
1. Install Samba
# yum install -y samba
# systemctl restart nmb
# systemctl restart smb
# netstat -tunpl | grep smb
# netstat -tunpl | grep nmbThe TCP ports 139 and 445 correspond to the smbd service for file and printer sharing, while the UDP ports 137 and 138 correspond to the nmbd service for NetBIOS name resolution.
2. Modify Configuration File
# cat smb.conf
[cloud]
comment = cloud
path = /it
writeable = No
write list = admin11
hosts allow = 127., 192.168.12., 192.168.13.Key settings include a description, the shared folder path, disabling write access for everyone, allowing only admin11 to write, and limiting access to specific network segments. Create the user and set a Samba password:
# useradd admin11
# smbpasswd -a admin11
# pdbedit -L # verify entry in the Samba database
# testparm # check configuration syntax3. Client Verification
# yum install -y samba-client.x86_64
# smbclient -L //192.168.5.100
# yum install -y cifs-utils
# mount -t cifs //192.168.5.100/cloud /mnt/cloud/ -o username=admin11
# touch 1.txt # create a test file on the client
# ll /it # verify the file appears on the serverAdjust permissions if needed by adding create mask = 0644 and directory mask = 0775 to the share definition.
4. Restrict Mount to admin11 Only
# cat smb.conf (add)
valid users = admin11
# Attempt to mount with a different user
# mount -t cifs //192.168.5.100/cloud /mnt/cloud/ -o username=admin12
# mount error(13): Permission deniedThe valid users directive ensures that only admin11 can mount the share.
5. Persist Mount via /etc/fstab
# cat cred.txt
username=admin11
password=123
# chmod 400 cred.txt
# echo "//192.168.5.100/cloud /mnt/cloud cifs defaults,credentials=/etc/samba/cred.txt 0 0" >> /etc/fstab
# mount -aThis stores credentials securely and mounts the share automatically at boot.
6. Separate Department Shares
# cat smb.conf
[cloud]
comment = cloud
path = /it
writeable = No
write list = admin11
create mask = 0644
browseable = No
directory mask = 0775
valid users = admin11
[hr]
comment = hr
path = /hr
writeable = No
write list = admin12
browseable = No
create mask = 0644
directory mask = 0775
valid users = admin12Each department has its own share with isolated access, preventing other departments from seeing unrelated directories.
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.
