Logo ← PostgreSQL Blog

Mounting a Windows File Server Share on RHEL 9 using CIFS Utilities

Mounting a Windows File Server share on a Red Hat Enterprise Linux (RHEL) 9 system enables seamless access to shared folders and files…

Mounting a Windows File Server Share on RHEL 9 using CIFS Utilities

Mounting a Windows File Server share on a Red Hat Enterprise Linux (RHEL) 9 system enables seamless access to shared folders and files residing on a Windows server. This guide provides a detailed walkthrough of the process using CIFS utilities.

Step 1: Install CIFS Utilities Packages

Before you can mount a Windows share, you need to have the necessary utilities installed. The CIFS utilities package provides the tools needed to mount and manage Windows shares on Linux.

dnf install cifs-utils
dnf install gettext  # This package is usually pre-installed

Explanation:

  • cifs-utils: This package contains the necessary tools to support the Common Internet File System (CIFS) protocol used by Windows shares.
  • gettext: This package provides internationalization and localization functions, which might be required by some utilities.

Step 2: Disable SELinux

SELinux (Security-Enhanced Linux) provides an extra layer of security by enforcing access controls. However, it might sometimes interfere with mounting Windows shares.

getenforce  # Check SELinux status
setenforce 0  # Temporarily set SELinux to permissive mode
vi /etc/selinux/config  # Edit SELinux configuration

Explanation:

  • getenforce: This command displays the current SELinux mode.
  • setenforce 0: Temporarily sets SELinux to permissive mode, allowing all actions but still logging violations.
  • Editing /etc/selinux/config: This file contains the SELinux configuration, and changing SELINUX=enforcing to SELINUX=disabled permanently disables SELinux.

Note: Disabling SELinux is generally not recommended unless absolutely necessary due to security implications.

Step 3: Create a User and Group

Create a dedicated user and group to access the shared files securely.

useradd kemal
passwd kemal  # Set a password for the user
groupadd dba  # Create a new group or use an existing one
usermod -aG dba kemal  # Add the user to the group

Explanation:

  • useradd: This command creates a new user.
  • passwd: Sets a password for the newly created user.
  • groupadd: Creates a new group.
  • usermod -aG: Adds the user to the specified group.

Step 4: Configure User Limits

Linux operating systems utilize the limits.conf file to impose resource usage limits on users. These limits are crucial for maintaining system stability and security.

vi /etc/security/limits.conf  # Edit limits configuration

Add the following lines:

kemal  soft  nproc  1024
kemal  hard  nproc  1024
kemal  soft  nofile 1024
kemal  hard  nofile 1024

Explanation:

  • kemal soft nproc 1024: The user 'kemal' can initiate a maximum of 1024 processes concurrently for their own tasks. If this limit is exceeded, a warning is issued but does not halt the process.
  • kemal hard nproc 1024: The user 'kemal' can initiate a maximum of 1024 processes concurrently for their own tasks. Exceeding this limit is strictly prohibited.
  • kemal soft nofile 1024: The user 'kemal' can open a maximum of 1024 files concurrently. If this limit is exceeded, a warning is issued but does not halt the file-opening operation.
  • kemal hard nofile 1024: The user 'kemal' can open a maximum of 1024 files concurrently. Exceeding this limit is strictly prohibited.

Step 5: Create Mount Point and Mount the Share

Prepare a directory for mounting the Windows share and then mount it.

mkdir -p /CBS/VTYS_BACKUP/
mount -t cifs //mavidepo1.itu.gov.tr/CografiBilgiSistemi/VTYS_BACKUP /VTYS_BACKUP /CBS/VTYS_BACKUP -o username=kemal.oz

Explanation:

  • mkdir: Creates a directory where the Windows share will be mounted.
  • mount -t cifs: Mounts the Windows share using the CIFS protocol.
  • -o username: Specifies the username to authenticate with the Windows server.

Step 6: Verify Mount Point

Confirm that the Windows share is successfully mounted using the df -h command.

df -h

Explanation:

  • df -h: Displays disk usage and file system information, allowing you to verify the mounted Windows share.

Step 7: Make Mount Persistent

To ensure the Windows share is mounted automatically at boot, add an entry to /etc/fstab.

vi /etc/fstab  # Edit fstab file

Add the following line:

//mavidepo1.itu.gov.tr/CografiBilgiSistemi/VTYS_BACKUP /VTYS_BACKUP cifs credentials=/etc/cifs-credentials,uid=kemal,gid=kemal,dir_mode=0750,file_mode=0750 0 0

Create a credentials file /etc/cifs-credentials:

vi /etc/cifs-credentials  # Create credentials file

Add:

user=kemal.oz
password=Sifre123
domain=BIM

Finally, use mount -a to verify and apply the changes:

mount -a
df -h  # Verify the mount again

Explanation:

  • /etc/fstab: This file contains static file system information, and adding an entry here ensures the Windows share is mounted at boot.
  • credentials: Specifies a file containing the username, password, and domain for authentication.
  • dir_mode and file_mode: Sets directory and file permissions for the mounted share.

Step 8: Unmounting the Filesystem

When you no longer need the mounted filesystem, you can unmount it.

umount /CBS/VTYS_BACKUP

Explanation:

  • umount: This command unmounts the specified filesystem.

By following these comprehensive steps, you should be able to mount a Windows File Server share on your RHEL 9 system securely and efficiently. Always adhere to best practices for security and consider the implications of disabling SELinux. For more detailed and technical articles like this, keep following our blog on Medium. If you have any questions or need further assistance, feel free to reach out in the comments below and directly.