How to mount Windows share on Red Hat Enterprise Linux system using CIFS?
Environment
- Red Hat Enterprise Linux (RHEL)
- CIFS
Issue
- How can Windows shares be mounted on Red Hat Enterprise Linux?
Resolution
- To run the following commands, you need to install
cifs-utils
package which providesmount.cifs
helper program. Some commands for mounting CIFS volume require the helper program to pre-process options before issuing amount()
syscall. -
Windows share can be mounted on RHEL system using
cifs
option ofmount
command as :# mount -t cifs -o username=<share user>,password=<share password> //WIN_PC_IP/<share name> /mnt
-
You can specify
iocharset
to convert local path names to/from UTF-8 if the server uses multi byte charset:# mount -t cifs -o iocharset=cp932,username=<share user>,password=<share password> //WIN_PC_IP/<share name> /mnt
-
In case your user is in windows domain then you can define the domain as follows:
# mount -t cifs -o username=<share user>,password=<share password>,domain=example.com //WIN_PC_IP/<share name> /mnt
-
By default, Windows shares are mounted with the full permission (0755) in Linux. To change the default permission use the
dir_mode
andfile_mode
options to set directory and file permission.# mount -t cifs -o username=<share user>,password=<sharepassword>,dir_mode=0755,file_mode=0755 //WIN_PC_IP/<share name> /mnt
-
To make the mount persistent across reboots, make the below entry to the
/etc/fstab
//WIN_PC_IP/<share name> /<mntpoint> cifs _netdev,username=<share user>,password=<share password>,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0
-
If a username/password/domain is needed, it is best not to leave it in fstab. In order to achieve this, the previous entry can be modified like so:
//WIN_PC_IP/<share name> /<mntpoint> cifs _netdev,credentials=/root/.credfile,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0
and then create the file /root/.credfile, with the following content (domain might not be mandatory):
username=<share user> password=<share password> domain=<share domain>
-
If you receive the following error when try to mount the share folder from windows machines
mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Please verify the permission on the folder on you windows machine and try again mount the share folder.
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