Operations 7 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step‑by‑Step Guide to Installing and Configuring Samba on Linux

1. Install Samba

# yum install -y samba
# systemctl restart nmb
# systemctl restart smb
# netstat -tunpl | grep smb
# netstat -tunpl | grep nmb

The 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 syntax

3. 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 server

Adjust 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 denied

The 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 -a

This 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 = admin12

Each department has its own share with isolated access, preventing other departments from seeing unrelated directories.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

System Administrationnetwork servicesfile sharingSambaCIFS
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.