How to mount Windows share on Red Hat Enterprise Linux system using SMB/CIFS?
Environment
- Red Hat Enterprise Linux 10
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 7
- SMB/CIFS
Issue
- How can Windows shares be mounted on Red Hat Enterprise Linux?
Resolution
Disclaimer: The configuration and troubleshooting steps outlined in this solution apply broadly to the Server Message Block (SMB) protocol suite. For the purposes of this documentation, the term "SMB" encompasses CIFS (Common Internet File System) as well as SMB versions 1.0, 2.x, and 3.x.
-
Before beginning, ensure the
cifs-utilspackage is installed:# yum install cifs-utils -yIt provided the
mount.cifshelper program, which is required it to pre-process options before issuing amount()system call. -
Then run the following command to mount the Windows share:
# mount -t cifs -o username=<username>,password=<password> //server/share /path/to/mountpoint-
The
iocharsetcan be specified to convert local path names to/from UTF-8, if the server uses multi-byte charset:# mount -t cifs -o iocharset=cp932,username=<username>,password=<password> //server/share /path/to/mountpoint -
In case the user is in Windows domain, the use the
domainmount option:# mount -t cifs -o iocharset=cp932,username=<username>,password=<password>,domain=example.com //server/share /path/to/mountpoint -
By default, Windows shares are mounted with full permission (0755) in RHEL. The mount options
dir_modeandfile_modecan be used to change it:# mount -t cifs -o username=<username>,password=<password>,dir_mode=0750,file_mode=0750 //server/share /path/to/mountpoint
-
-
To make the mount persist across reboots, add the below entry to the
/etc/fstab://server/share /path/to/mountpoint cifs _netdev,username=<username>,password=<password>,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0 -
A credentials file can be created to prevent exposing sensitive information such as usernames and passwords in
/etc/fstab:,-
Create the file
/root/.credentials, with the following content:username=<username> password=<password> -
If the user account is in a domain, make sure it's declared in the credentials file:
username=<username> password=<password> domain=<domain> -
Then add the
credentialsmount option in the/etc/fstabentry, passing the location of the credentials file created in the previous step://server/share /path/to/mountpoint cifs _netdev,credentials=/root/.credentials,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0
-
-
Run the following command so
systemdcan re-read/etc/fstaband generate the mount unit:# systemctl daemon-reload -
Finally, test if the SMB share can be mounted:
# mount /path/to/mountpointNote: If the
mountcommand returns the following error while attempting to get the share mounted, check the share permissions in the Windows system and try again.mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Root Cause
- Fore more information, please refer to
mount.cifs(8).
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments