Based on the Linux Master 1 exam syllabusReport an error
/etc/samba/smb.conf. The special sections are [global], [homes], and [printers]; every other section name is a share name.smbpasswd -a.smb.conf and the Linux filesystem permissions. After editing, validate the syntax with testparm.\\server\sharedfolder, but Windows uses SMB/CIFS (Server Message Block) while Linux traditionally uses NFS. Samba is the tool that bridges this gap.| Daemon | Role | Ports used |
|---|---|---|
smbd | File/printer sharing and user authentication | TCP 139, 445 |
nmbd | NetBIOS name service and network browsing (name-to-IP resolution) | UDP 137, 138 |
smbd is the core that handles the actual file transfers and authentication.nmbd is the name resolution service that makes the server name show up in Windows' "Network Neighborhood".smbd handles file sharing and authentication, and nmbd handles NetBIOS name resolution and browsing. The ports pair up too — smbd uses 139/445 (TCP), nmbd uses 137/138 (UDP).
After installing the Samba package, you normally manage the services with the following commands.
# Install packages (RHEL family)
yum install samba samba-client samba-common
# Start services / enable at boot (systemd)
systemctl start smb nmb
systemctl enable smb nmb
# Older versions (SysV init)
service smb startDistribution differences: the service names differ between distributions. On the RHEL/CentOS family they are smb and nmb; on the Debian/Ubuntu family the service names are smbd and nmbd. The configuration file location is the same on RHEL: /etc/samba/smb.conf.
/etc/samba/smb.conf.[ ].# /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = LINUXSRV
security = user
map to guest = Bad User
log file = /var/log/samba/log.%m
max log size = 50
[homes]
comment = Home Directories
browseable = no
writable = yes
[public]
comment = Public Share
path = /srv/samba/public
browseable = yes
writable = yes
guest ok = yesThere are three sections with special meaning.
| Section | Meaning |
|---|---|
[global] | Global settings that apply to the whole server: workgroup, security mode, logging, etc. |
[homes] | Automatically shares each user's home directory (special section) |
[printers] | Automatically shares the printers registered on the system (special section) |
[global] becomes a share name.\\LINUXSRV\public from Windows, the settings in the [public] section apply.[homes] is a magical section. When user kim connects, Samba clones the [homes] definition to create a virtual share called [kim] and points it at kim's home directory (/home/kim). That is why you do not need to define a separate share for every user.
security directive is the most important setting, because it determines the authentication method.| security value | Meaning |
|---|---|
user | (Default, recommended) The Samba server itself authenticates with username/password. Connecting users must have a Samba account |
share | Per-share password authentication (legacy, now deprecated) |
domain | Delegates authentication to a domain controller (a separate server) |
ads | Joins an Active Directory domain and authenticates through it |
workgroup : specifies the Windows workgroup name.server string : specifies the server description shown on the network.%v (version) and %m (client NetBIOS name).| Directive | Meaning | Example |
|---|---|---|
path | Actual directory path to share | path = /srv/samba/data |
comment | Share description | comment = Team Share |
browseable | Whether the share name appears in the network list | browseable = yes |
writable (= read only = no) | Whether writing is allowed | writable = yes |
read only | Read-only (the opposite of writable) | read only = yes |
guest ok (= public) | Allows guest access without a password | guest ok = yes |
valid users | Users/groups allowed access | valid users = kim, @sales |
write list | Users allowed to write on a read-only share | write list = admin |
create mask | Permission mask for newly created files | create mask = 0644 |
directory mask | Permission mask for newly created directories | directory mask = 0755 |
⚠️ Caution:
writable = yesandread only = nomean the same thing. If you write the two contradictorily at the same time, the last value wins. Groups get a leading@, as invalid users = @sales(the group designation symbol).
sales group) can read and write.[sales]
comment = Sales Team Data
path = /srv/samba/sales
valid users = @sales
writable = yes
browseable = yes
create mask = 0660
directory mask = 0770The double gate of permissions: access to a Samba share must pass two checks. (1) The Samba-level permissions in smb.conf, such as valid users/writable, and (2) the Linux filesystem permissions (chmod/chown) on that directory. If either one blocks you, access is denied. If "smb.conf is right but I can't write", nine times out of ten it is a Linux directory permission problem.
smb.conf, check the syntax with testparm to catch typos.# Syntax check + print a summary of the settings that will be applied
testparm
# Check a specific file
testparm /etc/samba/smb.confLoaded services file OK. appears in the output, the syntax is fine.Edit smb.conf → validate with testparm → systemctl restart smb → test the connection with smbclient. Work in this order.
security = user, connecting users must have a Samba password./etc/shadow)./etc/samba/smbpasswd file in the past).# 1) The Linux system account must exist first
useradd -s /sbin/nologin sambauser
# 2) Register the Samba password (interactive, enter the password twice)
smbpasswd -a sambausersmbpasswd options precisely.| Option | Meaning |
|---|---|
-a user | Add the user to the Samba database |
-x user | Delete the Samba user |
-d user | Disable the user account |
-e user | Enable a disabled account |
-n user | Set the password to none (null) |
(no option) user | Change that user's password |
⚠️ Trap: if the user is not in
/etc/passwdbefore you add them withsmbpasswd -a, you get an error. Do not mix up the order "Linux account first, Samba password afterward". You can also check the list of registered Samba users withpdbedit -L.
# List registered Samba users
pdbedit -L
# Including detailed information
pdbedit -Lvsmbclient is a tool that connects to SMB shares with an interactive interface similar to FTP.# List the shares the server offers (-L = list)
smbclient -L //LINUXSRV -U sambauser
# Connect to a specific share (enters an FTP-like prompt)
smbclient //LINUXSRV/sales -U sambauser
# After connecting, use ls, get, put, cd, etc. at the smb: \> prompt# Mount with the cifs type
mount -t cifs //LINUXSRV/sales /mnt/sales -o username=sambauser
# Example /etc/fstab entry
# //LINUXSRV/sales /mnt/sales cifs username=sambauser,password=secret 0 0Summary of mount types: Windows/Samba shares use mount -t cifs (formerly -t smbfs), and Linux-to-Linux uses mount -t nfs. If the exam asks for "the type for mounting a Windows shared folder on Linux", it is cifs.
# ① Install
yum install samba samba-client
# ② Prepare the shared directory + Linux permissions
mkdir -p /srv/samba/sales
chgrp sales /srv/samba/sales
chmod 2770 /srv/samba/sales # SGID for group inheritance
# ③ Edit smb.conf ([global] + [sales] sections)
vi /etc/samba/smb.conf
# ④ Validate the syntax
testparm
# ⑤ Register the Samba account
smbpasswd -a sambauser
# ⑥ Start the services
systemctl restart smb nmb
# ⑦ Open the firewall (firewalld)
firewall-cmd --add-service=samba --permanent
firewall-cmd --reload
# ⑧ Test the connection
smbclient -L //localhost -U sambauserTry it yourself: follow steps ① to ⑧ above once with two virtual machines (or local loopback). In particular, reading the warning messages that ④ testparm spits out gives you a feel for which directive is wrong. It is easy to forget the firewall in ⑦ and then flounder with "I can't connect".
Tomorrow we cover NFS, the standard for sharing between Linux systems, and compare how it differs from Samba.
/etc/samba/. It is made up of sections in square brackets.@ on a name means a group.-a add, -x delete, -d disable, -e enable.smb.conf and displays the values that will actually be applied.mount -t cifs).Click a choice to reveal the answer and explanation.
Question 1
Which daemon is responsible for the actual file sharing and user authentication in Samba?
Question 2
In smb.conf, which special section automatically shares each user's home directory?
Question 3
Which of the following correctly describes the smb.conf settings below?
```ini
[data]
path = /srv/data
valid users = @sales
writable = yes
```
Question 4
Which is the correct command to add a Samba user to the database?
Question 5
Which command checks for syntax errors after editing smb.conf?
Question 6
Which filesystem type is used when mounting a Windows/Samba shared folder on a Linux client?
Question 7
Which of the following correctly describes the security = user setting in the [global] section?