How to Mount a Windows Share on Linux Using CIFS

By 

Updated on

9 min read

Linux Mount CIFS Windows Share

When you need to access files from a Windows machine, NAS device, or Samba server, you can mount the shared folder directly into the Linux directory tree. After the mount is active, the remote files appear under a local path such as /mnt/win_share.

On Linux, Windows and SMB shares are commonly mounted with the cifs file system type through the mount command. The helper program is mount.cifs, which is installed by the cifs-utils package.

This guide explains how to install the required packages, mount Windows shares manually, use a credentials file, set permissions, create an automatic /etc/fstab mount, and troubleshoot common CIFS errors.

Quick Reference

TaskCommand
Install CIFS utilities (Ubuntu/Debian)sudo apt install cifs-utils
Install CIFS utilities (Fedora/RHEL)sudo dnf install cifs-utils
Mount a sharesudo mount -t cifs -o username=USER //SERVER/SHARE /mnt/point
Mount with credentials filesudo mount -t cifs -o credentials=/etc/win-credentials //SERVER/SHARE /mnt/point
Unmount a sharesudo umount /mnt/point
Auto-mount via fstab//SERVER/SHARE /mnt/point cifs credentials=/etc/win-credentials,_netdev,nofail,x-systemd.automount 0 0

Installing CIFS Utilities

To mount a Windows share on a Linux system, you need the cifs-utils package installed.

On Ubuntu, Debian, and derivatives:

Terminal
sudo apt update
sudo apt install cifs-utils

On Fedora, RHEL, and derivatives:

Terminal
sudo dnf install cifs-utils

Mounting a CIFS Windows Share

The basic syntax for mounting a CIFS share is:

txt
mount -t cifs -o OPTIONS //SERVER/SHARE /mount/point

Mounting a remote Windows share is similar to mounting regular file systems.

First, create a directory to serve as the mount point for the remote Windows share:

Terminal
sudo mkdir /mnt/win_share

Run the following command as root or a user with sudo privileges to mount the share:

Terminal
sudo mount -t cifs -o username=<win_share_user> //WIN_SHARE_IP/<share_name> /mnt/win_share

You will be prompted to enter the password:

output
Password:

On success, no output is produced.

To verify that the remote Windows share is successfully mounted, use df -h :

Terminal
df -h /mnt/win_share

You can also use findmnt to show the source, target, file system type, and active mount options:

Terminal
findmnt /mnt/win_share

Once the share is mounted, the mount point becomes the root directory of the mounted file system. You can work with the remote files as if they were local files.

Specifying the Password on the Command Line

The password can also be provided directly on the command line:

Terminal
sudo mount -t cifs -o username=<win_share_user>,password=<win_share_password> //WIN_SHARE_IP/<share_name> /mnt/win_share

This approach is less secure because the password is visible in the process list and shell history.

Specifying a Domain

If the user is in a Windows workgroup or domain, you can set it with the domain option:

Terminal
sudo mount -t cifs -o username=<win_share_user>,domain=<win_domain> //WIN_SHARE_IP/<share_name> /mnt/win_share

Using a Credentials File

For better security, it is recommended to use a credentials file instead of passing the username and password on the command line.

Create a file at /etc/win-credentials with the following format:

/etc/win-credentialstxt
username=user
password=password
domain=domain

The domain line is optional. Use it when the account belongs to a Windows domain or workgroup. Do not add spaces around the = signs.

Warning
The credentials file contains a plaintext password. Store it outside your project directories, do not commit it to version control, and keep it readable only by root.

The file must not be readable by other users. To set the correct permissions and ownership , run:

Terminal
sudo chown root: /etc/win-credentials
sudo chmod 600 /etc/win-credentials

To use the credentials file when mounting, specify it with the credentials option:

Terminal
sudo mount -t cifs -o credentials=/etc/win-credentials //WIN_SHARE_IP/<share_name> /mnt/win_share

Setting Permissions and Ownership

When the SMB server does not provide Unix ownership information, files and directories usually appear as owned by root on the Linux client. Use uid and gid to map the mounted files to a local user and group.

First, check your user’s UID and GID:

Terminal
id

The output looks similar to this:

output
uid=1000(linuxize) gid=1000(linuxize) groups=1000(linuxize),27(sudo)

In this example, both the UID and GID are 1000.

To mount the share as that user, pass the values with the uid and gid options:

Terminal
sudo mount -t cifs -o credentials=/etc/win-credentials,uid=1000,gid=1000 //WIN_SHARE_IP/<share_name> /mnt/win_share

Use dir_mode to set directory permissions and file_mode to set file permissions:

Terminal
sudo mount -t cifs -o credentials=/etc/win-credentials,uid=1000,gid=1000,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/<share_name> /mnt/win_share

These options control how ownership and mode bits appear on the Linux client. The server still enforces its own share permissions and Windows ACLs, so uid, gid, file_mode, and dir_mode cannot grant access that the Windows or Samba server denies.

To set additional mount options , add them as a comma-separated list after the -o option. Run man mount.cifs in your terminal for a full list of CIFS-specific options.

Specifying the SMB Protocol Version

Modern Linux kernels auto-negotiate the highest SMB2 or SMB3 protocol version supported by both the client and server. In most cases, you do not need to specify the version manually.

If you are connecting to an older NAS device or Samba server that requires a specific protocol version, use the vers option:

Terminal
sudo mount -t cifs -o credentials=/etc/win-credentials,vers=3.0 //WIN_SHARE_IP/<share_name> /mnt/win_share

Common values are 3.1.1, 3.0, and 2.1. Avoid using 1.0 because SMB1 is deprecated, weaker than modern SMB versions, and disabled by default on many current systems.

Auto Mounting with fstab

When the share is manually mounted with the mount command, it does not persist after a reboot.

The /etc/fstab file contains a list of entries that define where, how, and what file systems will be mounted on system startup.

To automatically mount a Windows share when your Linux system starts up, define the mount in the /etc/fstab file. The line must include the hostname or the IP address of the Windows PC, the share name, and the mount point on the local machine.

Open the /etc/fstab file with your text editor :

Terminal
sudo nano /etc/fstab

Add the following line to the file:

/etc/fstabtxt
//WIN_SHARE_IP/share_name  /mnt/win_share  cifs  credentials=/etc/win-credentials,uid=1000,gid=1000,file_mode=0755,dir_mode=0755,_netdev,nofail,x-systemd.automount  0  0
  • credentials=/etc/win-credentials - reads the username, password, and optional domain from the protected credentials file.
  • uid=1000,gid=1000 - maps files and directories to the local user and group.
  • file_mode=0755,dir_mode=0755 - controls the mode bits shown on the Linux client.
  • _netdev - marks the entry as a network mount so the system orders it after the network is available.
  • nofail - lets the boot continue if the share is temporarily unavailable.
  • x-systemd.automount - creates an automount unit on systemd-based distributions, so the share is mounted when the path is accessed.

If you are using a systemd-based distribution, reload systemd so it notices the updated fstab entry:

Terminal
sudo systemctl daemon-reload

Before rebooting, test the fstab entry with:

Terminal
sudo mount -a

If the command returns no output, the fstab entry was accepted. You can also verify the mount with:

Terminal
findmnt /mnt/win_share

Next time you reboot the system, the Windows share will be mounted automatically or on first access when x-systemd.automount is used.

Unmounting a Windows Share

The umount command detaches (unmounts) the mounted file system from the directory tree.

To detach a mounted Windows share, use the umount command followed by the directory where it has been mounted:

Terminal
sudo umount /mnt/win_share

If the CIFS mount has an entry in the fstab file and you no longer need it, remove that entry.

The umount command will fail to detach the share when it is in use. To find out which processes are accessing the share, use the fuser command:

Terminal
fuser -m /mnt/win_share

Once you find the processes, you can stop them with the kill command and unmount the share.

If you still have problems unmounting the share, use the -l (--lazy) option, which allows you to unmount a busy file system as soon as it is not busy anymore:

Terminal
sudo umount -l /mnt/win_share

Troubleshooting

mount: wrong fs type, bad option, bad superblock
The cifs-utils package is not installed. Install it with sudo apt install cifs-utils (Ubuntu/Debian) or sudo dnf install cifs-utils (Fedora/RHEL).

mount error(13): Permission denied
The username or password is incorrect. Double-check your credentials. If the Windows share requires a domain, add the domain= option.

mount error(112): Host is down
This may mean the client and server cannot agree on an SMB protocol version. Try specifying the version explicitly with vers=3.0 or vers=2.1. Also verify that the server is reachable and that SMB service is running.

mount error(115): Operation now in progress
The server is unreachable. Verify the IP address and make sure the server is online and the firewall allows traffic on port 445.

mount error(95): Operation not supported
The server may require a different SMB dialect or security mode. Start by trying vers=3.0, then check the server’s SMB settings.

Share does not mount at boot (fstab)
Make sure the fstab entry includes _netdev so the system treats it as a network mount. On systemd-based systems, add x-systemd.automount to avoid boot delays and mount the share when the path is accessed. Adding nofail prevents boot failures if the share is temporarily unavailable.

Permission denied when writing to mounted share
The local mount options may not map the share to the user you expect, or the server may deny write access. Add uid=<your_uid>,gid=<your_gid>,file_mode=0755,dir_mode=0755 to the mount options, then check the Windows or Samba share permissions if writes still fail.

Password contains a comma
Passwords that contain commas can fail when passed directly in the mount command because CIFS options are comma-separated. Use a credentials file instead.

FAQ

What is the difference between CIFS and SMB?
SMB (Server Message Block) is the protocol, and CIFS (Common Internet File System) is an older dialect of SMB. On Linux, the mount -t cifs command supports modern SMB versions (2.x and 3.x) despite the CIFS name.

Is mount.cifs different from mount -t cifs?
mount -t cifs calls the mount.cifs helper from the cifs-utils package. In day-to-day use, both forms mount the same type of SMB share.

Can I mount a Windows share without a password?
Yes. For guest access, use username=guest,password= in the mount options. The Windows share must be configured to allow anonymous access.

How do I find the IP address of the Windows machine?
On the Windows machine, open Command Prompt and run ipconfig. The IPv4 address is what you need for the mount command.

Is CIFS mounting secure?
Modern SMB versions are much safer than SMB1, and SMB3 supports encryption when the server and client are configured for it. For additional security, use a credentials file with strict permissions (chmod 600) and avoid passing passwords on the command line.

What is the alternative to CIFS for mounting remote directories?
You can use NFS for Linux-to-Linux file sharing or SSHFS for mounting directories over SSH.

Conclusion

If a CIFS mount works when you run it by hand but fails after a reboot, the problem is almost always boot ordering: add _netdev so systemd waits for the network, nofail so a missing share does not stall the boot, and x-systemd.automount so the share mounts on first access. For Linux-to-Linux shares, consider NFS instead, which carries Unix ownership natively and skips the uid/gid mapping shown here.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page