ARTICLE - Cloud Servers & Compute

Mount a Samba Share on CentOS with CIFS

A successful CIFS mount depends on four separate checks: client tools, the server share and its ACLs, network reachability, and valid credentials. Diagnose those conditions independently instead of repeatedly changing SMB options.

2023-04-03 cnblogs.com (CQZHUOMI) 74 views
Advertisement

On a CentOS client, mount -t cifs attaches a Samba share, but success also depends on the share name, authentication, directory permissions and TCP 445 reachability. This guide covers a Linux CIFS client: test a one-time mount first, then decide whether it belongs in the boot configuration. Replace all example addresses and names; do not expose SMB to the public Internet.

CIFS mount path Client tools Auth and SMB TCP 445 Share and ACL For error 13, check credentials and server ACLs; for timeouts, check the network Process overview; the server must authorize this client
Figure 1: CIFS mount path. Scope: process overview; authentication and directory permissions are controlled by the Samba server.

First confirm that the client has mount.cifs and that the server has created the share. Replace 192.0.2.10 and team with the actual server address and share name. Keep the client and server on a controlled network.

Check the client package and network

The CentOS 7 example uses yum. CentOS Linux 7 reached end of life on 2024-06-30, as recorded on the CentOS project lifecycle page, and no longer receives regular security updates. For an existing host, confirm that package sources are trusted and available before installing; use a supported system for new deployments. Other distributions may use a different package manager.

yum install -y cifs-utils nmap-ncat
command -v mount.cifs
nc -vz 192.0.2.10 445

command -v should print the executable path, and the port test should report a successful connection. If the first check fails, inspect the package installation; if the second fails, check routing, firewalls and cloud security rules before changing SMB protocol options.

Mount with a credentials file

For ongoing use, keep passwords out of command arguments, scripts and /etc/fstab. Create a file readable only by root, then enter the server account with an editor; do not type a real password directly into a shell command. See the mount.cifs manual for credential-file and mount-option details.

install -o root -g root -m 600 /dev/null /root/.smbcredentials
vi /root/.smbcredentials

Use this format in the file, replacing the values with the Samba account details:

username=replace-with-share-account
password=replace-with-account-password

Confirm that the file is owned by root with mode 600, then create a mount point and connect. By default, the client negotiates the SMB version with the server. Specify a version such as vers=3.0 only when the server administrator confirms support and negotiation is the problem. Do not enable SMB1 as a general compatibility workaround.

mkdir -p /mnt/team
mount -t cifs //192.0.2.10/team /mnt/team \
  -o credentials=/root/.smbcredentials,iocharset=utf8
mountpoint -q /mnt/team && findmnt -M /mnt/team
ls -la /mnt/team

On success, findmnt should show the remote share as the source and cifs as the filesystem type. ls should list files the account is allowed to read. For a read-only share, add ro; client-side options do not replace server ACLs.

Configure boot mounting and recovery

Edit /etc/fstab only after a one-time mount has passed verification and the host needs an automatic mount. Back up the file first; the mount point, share path and credentials file must exist. _netdev marks the network dependency. nofail lets boot continue if the mount fails, but applications still cannot access an unmounted share.

//192.0.2.10/team  /mnt/team  cifs  credentials=/root/.smbcredentials,iocharset=utf8,_netdev,nofail  0  0

After saving, test this entry with mount /mnt/team and confirm it with findmnt -M /mnt/team. Do not treat mount -a as a harmless check: it attempts every entry in the file. See the systemd.mount manual for network mount and nofail behavior. If this mount fails, remove the line or restore the backup, then confirm the system can still boot. Do not unmount while applications are using the share; check usage and schedule umount /mnt/team for a maintenance window.

Diagnose by symptom

  • unknown filesystem type 'cifs': check whether cifs-utils is installed and the kernel provides CIFS support.
  • mount error(13): this does not prove the password is wrong. Check the share name, server authentication policy, account authorization and directory ACLs.
  • mount error(112) or a connection timeout: check the server address, route, TCP 445 and firewalls from the client. Never expose port 445 to the public Internet.
  • The mount works but writes fail: inspect server-side share permissions, filesystem ACLs and account mapping. A client-side chmod may not change server authorization.

Start by checking whether findmnt -M /mnt/team shows a mount, then distinguish network, authentication and directory-authorization failures. Server logs can identify rejected authentication. Do not enable SMB1 before confirming the server's supported protocols.

Limitations

  • This covers the client mount only, not smb.conf, Samba user creation or server-side ACL configuration.
  • The package command uses the CentOS 7 convention. CentOS Linux 7 is end of life; package names, kernel CIFS capabilities and mount.cifs versions vary on supported distributions.
  • nofail changes boot behavior; it does not make the share available. Applications that depend on the directory still need to handle unavailable storage.
  • A root-only credentials file prevents ordinary local users from reading it, but not root. Restrict host administration and include the credential in your rotation process.

FAQ

When should I avoid enabling SMB1?

Do not use SMB1 as a general compatibility setting. Normally, let the CIFS client and server negotiate; specify vers only when the server administrator confirms support for that version and logs show a negotiation mismatch. If a server supports only SMB1, upgrade or isolate it rather than weakening a modern client's protocol policy.

Does mount error(13) mean the Samba password is wrong?

Not necessarily. Error 13 means access was denied. Check the credentials, share name, server authentication policy, account authorization for that share and the underlying directory ACL. Use server logs to identify the rejected step, then change that setting only. Do not bypass authorization by enabling anonymous write access.

What prerequisites apply when an application depends on a CIFS mount?

Confirm that CIFS is actually mounted. nofail lets boot continue after a mount failure, so the path may still be a local directory. Before starting a dependent service, check findmnt -M /mnt/team and configure failure handling. nmap-ncat can test TCP 445 reachability, but it does not verify share authorization.

Related Providers

  • Alibaba Cloud ECS: for running the client and file server on a private network and checking instance network rules in the console.
  • Tencent Cloud: for VPC-hosted clients accessing an SMB share while checking both instance networking and access-control rules.

For server-side sharing, see CentOS Samba share configuration. More cloud-host guidance is in the cloud servers category.

Community & Resources

Original source: cnblogs.com (CQZHUOMI) ↗