هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
dnf -y install cifs-utils
install -m 600 /dev/null /root/.smb-fs1
printf 'username=svc-linux\npassword=%s\ndomain=CORP\n' '<password>' > /root/.smb-fs1
mkdir -p /mnt/invoices
mount -t cifs //fs1.corp.example.com/Invoices /mnt/invoices -o credentials=/root/.smb-fs1,uid=app,gid=app,vers=3.1.1,seal
ls /mnt/invoices | headOn Ubuntu: apt-get install -y cifs-utils.
Step by step
- Use a service account with only the rights the job needs (read-only if it only reads) — not your own Windows login.
- Keep the password in a credentials file with
600rights (quick answer), never in fstab or on the command line. - The mount options:
| Option | Means |
|---|---|
credentials=FILE | User, password, domain from the file. |
uid=app,gid=app | Files appear owned by this Linux user (SMB has no Linux owners). |
file_mode=0640,dir_mode=0750 | Linux rights shown for files and folders. |
vers=3.1.1 | SMB protocol version (3.x; never SMB1). |
seal | Encrypt the traffic (SMB 3). |
ro | Read-only mount. |
- Mount at boot:
//fs1.corp.example.com/Invoices /mnt/invoices cifs credentials=/root/.smb-fs1,uid=app,gid=app,file_mode=0640,dir_mode=0750,vers=3.1.1,seal,_netdev,nofail 0 0- SELinux — for a web server or service that reads the share, set a label at mount time:
context=system_u:object_r:httpd_sys_content_t:s0(Or turn on the boolean that fits, for example setsebool -P httpd_use_cifs on.)
- Find the shares a server offers (needs
samba-client):
smbclient -L //fs1.corp.example.com -U 'CORP\svc-linux'Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
mount error(13): Permission denied | Wrong user/password/domain, or no share rights. | Check the credentials file (no spaces, right domain); rights on the Windows side. |
mount error(95): Operation not supported | SMB version not supported by the server. | Try vers=3.0 (never 1.0). |
mount error(112): Host is down | Port 445 blocked or wrong name. | nc -zv fs1.corp.example.com 445; DNS. |
mount error(2): No such file or directory | Share name wrong. | smbclient -L to list the share names. |
| Everything is owned by root | No uid=/gid= options. | Add uid=, gid=, file_mode, dir_mode. |
| Boot hangs on the mount | No _netdev/nofail. | Add both (or use a systemd automount: x-systemd.automount). |
Go further
- Command pages: mount, findmnt, umount.
- Next how-tos: Share a folder with NFS, Mount a disk at boot with fstab, Find and fix SELinux denials.
- Full guide: Samba server and clients.
1Why use a credentials file for a CIFS mount?
The password stays out of fstab, the command line and ps; the file has 600 rights.
2Why are all files owned by root after the mount, and how do you change it?
SMB has no Linux owners; set uid=, gid= (and modes) in the mount options.