Mount a Windows share on Ubuntu: fstab, errors
Mount an SMB share from Windows, Samba or a NAS on Ubuntu 24.04 or 26.04. Keep an offline share from hanging boot, and decode mount errors 13, 112, 115 and 127.
How do you mount a Windows share on Ubuntu Server?
To mount a Windows share on Ubuntu Server, install cifs-utils, put the login in a credentials file that only root can read, and run mount -t cifs with an explicit vers=. To make the mount permanent, add one line to /etc/fstab with _netdev, nofail and x-systemd.automount. Those options stop an offline share from blocking the boot.
The steps are the same whether the share lives on Windows or on a Samba server. A NAS (network-attached storage) box that offers SMB shares counts as an SMB server here. SMB (Server Message Block) is the file-sharing protocol all of them speak. CIFS (Common Internet File System) is the name the Linux client still uses for it.
This guide covers the client side on Ubuntu 24.04 and 26.04. It starts with a mount you run by hand and turns it into a safe fstab line. Then it decodes the mount error(N) lines you will meet. The last part covers a VPS that needs a share at home or in an office, without putting that share on the internet.
Install cifs-utils and note the versions
sudo apt update
sudo apt install -y cifs-utils
mount.cifs -V
uname -rThe cifs-utils package provides mount.cifs, the helper that mount -t cifs calls. As of 10 November 2026, Ubuntu 24.04 ships it as 2:7.0-2ubuntu0.6 and Ubuntu 26.04 ships 2:7.4-1ubuntu0.26.04.4. Both were published on 19 October 2026 in the security pocket.
The helper reads your options and starts the mount. The SMB client itself is the cifs module in the kernel, so the kernel decides most of the behaviour you see. A 24.04 server install uses the GA (general availability) kernel by default, which is 6.8. The newer HWE (hardware enablement) kernel is optional. Ubuntu 26.04 uses kernel 7.0. Write both version numbers down. Anyone helping you will ask for them first.
One more thing to know about the manual. The Ubuntu mount.cifs(8) man page says it describes version 2.18 of the CIFS VFS, which is roughly kernel 5.0. Your kernel is newer, so keep the kernel's own CIFS usage document open as a second reference.
Store the password in a root-only credentials file
A password typed on the command line ends up in your shell history. The man page also warns that a comma inside a command-line password breaks option parsing. The credentials= option avoids both problems. It names a file that holds the login, and the man page says this is preferred over putting passwords in a shared file. It also says to protect that file properly, but it does not name a mode. This guide uses mode 600 with root as the owner, which means only root can read it.
sudo install -d -m 700 -o root -g root /etc/smb-credentials
sudo install -m 600 -o root -g root /dev/null /etc/smb-credentials/projects
sudoedit /etc/smb-credentials/projectsPut the login in the file, one value per line:
username=backupuser
password=your-share-password
domain=WORKGROUPLeave out the domain= line unless the account belongs to a Windows domain. Do not put spaces around the = sign. The man page lists a known bug: the file does not handle user names or passwords that start with a space.
sudo ls -l /etc/smb-credentials/projectsThe line should start with -rw------- and show root root as the owner and group. If those ten characters look like noise, how to read Linux file permissions such as drwxr-xr-x explains each position.
Mount the share by hand first
Test the options with a manual mount before you touch /etc/fstab. A mistake here costs you one error message. The same mistake in fstab can cost you a boot.
sudo mkdir -p /mnt/projects
sudo mount -t cifs //192.0.2.10/projects /mnt/projects -o credentials=/etc/smb-credentials/projects,vers=3.1.1,uid=1000,gid=1000,file_mode=0640,dir_mode=0750
findmnt /mnt/projects//192.0.2.10/projects is the server address followed by the share name. 192.0.2.10 is a documentation address, so replace it with your server's IP address or host name. Replace 1000 with the output of id -u and id -g for the local user who will use the files.
findmnt should print one line with cifs in the FSTYPE column. If mount printed mount error(...) instead, skip ahead to the troubleshooting section. When the test works, unmount it with sudo umount /mnt/projects before you add the fstab line.
If you set no port= option and no connection to the server exists yet, the client tries TCP port 445 first and then falls back to port 139. You rarely need to set port=.
Why set vers= instead of letting the client negotiate?
With no vers= option, mount.cifs uses vers=default. Since kernel 4.13.5 that means the client and server negotiate the highest version both support, at SMB 2.1 or above. The kernel documentation says this usually ends at SMB 3.1.1.
Negotiation picks the best version both sides offer. It does not tell you when that version is lower than you expected. If a server only offers SMB 2.1, a default mount still succeeds at 2.1. An explicit value turns that silent result into an error you can see. The man page accepts 1.0, 2.0, 2.1, 3.0, 3.02 (or 3.0.2), 3.1.1 (or 3.11), 3 and default.
vers=3.1.1pins the newest dialect. Use it when you know the server supports it.vers=3means SMB 3.0 or later. The kernel docs say it forces SMB3 or later and never uses 2.1.
You can see which dialect a mount actually uses. In the kernel source, the vers= value in a mount's option list comes from the live server connection. It therefore shows the negotiated result even when you asked for default:
findmnt -o TARGET,OPTIONS /mnt/projectsSMB1 is a different matter. The man page says SMB1 is no longer requested by default at mount time. You only get it by writing vers=1.0, and the kernel docs describe that dialect as much older and less secure than the default. Most servers will not offer it anyway. Microsoft says SMBv1 is not installed by default in any edition of Windows 11 or Windows Server 2019 and later. Samba's default server min protocol is SMB2_02, so a Samba server refuses SMB1 unless someone changed that setting. To block the legacy dialects on the client too, the man page points to the module option disable_legacy_dialects=y:
echo 'options cifs disable_legacy_dialects=y' | sudo tee /etc/modprobe.d/cifs-no-smb1.confThe option applies the next time the cifs module loads. Reboot, or unmount every CIFS share and reload the module.
Why does chmod not change files on the share?
On a CIFS mount, the owner and the mode bits you see are often not stored anywhere on the server. The client fills them in. These options control what it fills in:
uid=andgid=set the owner of files and directories when the server sends no ownership information. Both default to 0, which is why an untuned mount shows every file as owned by root.file_mode=anddir_mode=set the mode bits for files and directories when the server does not support the CIFS Unix extensions.forceuidandforcegidmake the client ignore ownership the server does send, and use youruid=andgid=instead.
The kernel documentation says chmod can change the mode only when the CIFS Unix extensions are enabled on both the server and the client. Windows does not implement those extensions. On a Windows share, the documented way to change what ls -l shows is to change uid=, gid=, file_mode= or dir_mode= and mount again. Ownership has the same limit, so the chown command is the wrong tool here.
There is a quick way to see which case you are in. In the kernel source, file_mode= and dir_mode= appear in the mount's option list only when the Unix extensions are off for that share. If findmnt -o OPTIONS /mnt/projects shows them, the mode bits are synthetic.
Samba is less simple. Samba's unix extensions setting is a synonym for smb1 unix extensions, which covers the old SMB1 extensions. A separate smb3 unix extensions setting exists, and its default is yes. Do not assume chmod works on a Samba share mounted with vers=3.1.1. Test it on a scratch file first.
The client-side mode bits are only half of the access check. The server still checks every request against the account in your credentials file. The noperm option turns off the client-side checks completely. The kernel docs note that this can expose files on the mount to other local users, while the server's checks still apply. Leave it off unless only one local user can reach the mount point. The cifsacl option reports mode bits based on the Windows ACL (access control list) instead. The kernel docs mark it experimental, and the man page says it needs cifs.idmap and winbind for ID mapping.
What must the Windows or NAS side allow?
The server decides many mount failures. Check it before you change client options.
On Windows, see whether SMBv1 is enabled on the server side with PowerShell: Get-SmbServerConfiguration | Format-List EnableSMB1Protocol. You want it off. A Linux client does not need it.
Microsoft also documents a change in Windows 11 24H2 and Windows Server 2025: SMB signing is required by default. Microsoft says this can block connections to workgroup computers, guest-authenticated shares, or third-party SMB servers that do not support signing. Microsoft says not to disable signing or SMB versions as a workaround. On those versions, the built-in firewall rules also no longer open the NetBIOS ports 137 to 139. The client's fallback to port 139 will not help there.
On a Samba server, check server min protocol in smb.conf. The default is SMB2_02. Also check hosts allow. When it is not set, every host is permitted.
Add the share to /etc/fstab so boot never waits on it
An fstab line has six fields: the share, the mount point, the type, the options, a dump flag and a check order. This line is the manual mount from above plus the options that make it safe at boot:
//192.0.2.10/projects /mnt/projects cifs credentials=/etc/smb-credentials/projects,vers=3.1.1,uid=1000,gid=1000,file_mode=0640,dir_mode=0750,_netdev,nofail,x-systemd.automount,x-systemd.mount-timeout=30 0 0Each added option has one job:
_netdevtells systemd the mount needs the network. systemd then orders the mount betweenremote-fs-pre.targetandremote-fs.target, pulls innetwork-online.target, and starts the mount after it.nofailmakes the mount wanted, not required, byremote-fs.target. The boot continues without waiting for the mount unit.x-systemd.automountcreates an automount unit for/mnt/projects. The real mount starts the first time something accesses the path, not during boot.x-systemd.mount-timeout=30sets how long systemd waits for the mount command to finish. Without it, the limit comes fromDefaultTimeoutStartSec=.
The last two fields are 0 0. The second zero matters: an fs_passno of 0 means no filesystem check, which is the only sensible value for a network share.
mount.cifs does not need to understand the systemd options. In the upstream mount.cifs source, _netdev and every option that starts with x- are accepted and ignored. The same source also handles nofail itself: when the connection fails, it returns success instead of an error. That upstream code is newer than the Ubuntu builds. Treat the exit status as a hint, and confirm a mount with findmnt.
How do you test the fstab line before you reboot?
The obvious test is sudo mount -a. It mounts everything in fstab except entries marked noauto. But the mount(8) man page itself calls mount -a a bad practice for checking fstab, and recommends findmnt --verify instead. Use each tool for its own job.
sudo findmnt --verify
sudo systemctl daemon-reload
systemd-escape -p --suffix=automount /mnt/projects
sudo systemctl start mnt-projects.automount
ls /mnt/projects
findmnt /mnt/projectsfindmnt --verify checks that /etc/fstab parses and that each entry is usable. Its man page does not say it contacts the server, so a clean result does not prove the share is reachable. Fix anything it reports before you go on.
daemon-reload matters because systemd turns fstab into mount units early at boot and again when the system manager reloads its configuration. Until then, systemd does not know about your new line. systemd-escape prints the automount unit name for your mount point, which is mnt-projects.automount for /mnt/projects. Starting that unit and then running ls on the path triggers the real mount. findmnt should then show the cifs mount.
If the mount does not appear, read the mount unit's log:
journalctl -u mnt-projects.mount -n 50When the automount path works by hand, a reboot uses the same units. Reboot once while you can still reach the console. After the reboot, list the directory and check findmnt /mnt/projects.
Mount error codes: what each one means and what to check
mount.cifs prints failures as mount error(N): followed by the system's text for that error number. For most numbers it then adds one line: Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg). That advice is the core of every fix below, because the kernel log usually holds the real reason.
The mount.cifs source gives special text to only a few numbers. In this list, those are 112 and 115. The man pages and the kernel CIFS usage document explain none of these codes. For the other codes, this section gives the meaning of the number and the checks that narrow it down. It does not guess at a cause the documentation does not state.
The numbers below come from the kernel's generic errno headers. The errno(3) man page warns that numbers can differ between CPU architectures. To check one on your own machine, install moreutils and run errno 112.
These diagnostics help with every code:
sudo dmesg | tail -n 30
sudo cat /proc/fs/cifs/DebugData
echo 7 | sudo tee /proc/fs/cifs/cifsFYI
sudo dmesg | tail -n 60
echo 0 | sudo tee /proc/fs/cifs/cifsFYIDebugData shows the active CIFS sessions and shares, the enabled features and the cifs.ko version. Writing 7 to cifsFYI logs extra debug detail to the kernel log. Run the failing mount again between the third and fourth commands. Debug logging is verbose and can slow the system, so write 0 when you are done.
mount error(13): Permission denied
Error 13 is EACCES. mount.cifs has no special handling for it, so the reason is in dmesg. Check the inputs you control first. Open the credentials file and confirm it has username= and password= on separate lines, with no spaces around the values. A leading space is the documented bug from earlier. Then confirm that the same account can open the share from another client. That tells you whether the server accepts this login at all.
mount error(115): Operation now in progress
Error 115 is EINPROGRESS. The mount.cifs source treats it the same way as a refused or unreachable connection. It prints could not connect to with the address, then tries the next address it has. When no addresses are left, it prints Unable to find suitable address. In plain terms, the TCP connection to the server never completed. Check that port 445 answers from this machine:
sudo apt install -y netcat-openbsd
nc -vz -w 5 192.0.2.10 445The -z flag only checks whether something listens, without sending data. -w 5 gives up after five seconds. A timeout means the traffic does not get through. Check the firewalls on both ends and the route from this machine. Checking whether a port is open from Linux covers more tools for the same test.
mount error(112): Host is down
Error 112 is EHOSTDOWN. For this one, mount.cifs prints Server abruptly closed the connection, with a hint that the server may not support the SMB version the client tried. The TCP connection worked, and then the server closed it. Check which dialects the server allows, with the Windows and Samba checks above. Then try vers=3.0 and vers=2.1 by hand to find the newest one that mounts.
The same message suggests vers=1.0. Treat that as a diagnostic, not a fix. SMB1 is the old, less secure dialect. A server that only speaks SMB1 belongs on an isolated network or on a replacement list.
mount error(22): Invalid argument
Error 22 is EINVAL. mount.cifs passes it on without extra text, so read dmesg right after the failure. Then check your option string. Compare vers= with the accepted list in the version section. Look for a misspelled option name or a stray space after a comma. If nothing stands out, remove options one at a time, starting from the end, until the mount works. The last option you removed is the one to look at.
mount error(95): Operation not supported
Error 95 is EOPNOTSUPP. The kernel header describes it as Operation not supported on transport endpoint. mount.cifs adds nothing, so start with dmesg and DebugData. Then mount again with an explicit vers= value instead of default. A fixed dialect makes the kernel log easier to compare between attempts.
mount error(5): Input/output error
Error 5 is EIO, a generic I/O error. Neither the man pages nor the kernel docs say what it means for a mount. Turn on cifsFYI, repeat the mount, and read the kernel log. Also read /proc/fs/cifs/Stats, which counts reconnects. If you ask for help, include uname -r, mount.cifs -V and the DebugData output.
mount error(127): Key has expired
Error 127 is EKEYEXPIRED, and Key has expired is the kernel's own text for it. You meet this code with Kerberos mounts, which use sec=krb5. For those, the kernel calls the cifs.upcall helper through request-key. The helper looks at the Kerberos ticket cache named by $KRB5CCNAME of the process that started the mount. The cruid= option sets the user who owns that cache. The kernel docs require cifs.upcall version 1.2 or later for Kerberos mounts.
The documentation does not tie error 127 to one specific Kerberos state. Check the parts you can see. Confirm that sec=krb5 is in your options, and that cruid= names the user whose tickets you expect. As that user, run klist to list the tickets in the cache with their expiry times. Then read dmesg for the lines that came with the failure.
Reaching a home or office share from a VPS without opening port 445
Port 445 must never face the internet. Microsoft's own guidance is to block TCP 445 inbound from the internet at the firewall. Never forward 445 or 139 from a home router to a NAS so that a VPS can reach it. Put the VPS inside a private network with the share instead. How ports work on Linux explains why an open port answers anyone who asks.
Over WireGuard. wg-quick builds routes from each peer's AllowedIPs and adds them to the routing table. On the VPS, the peer for your home router must list the home subnet in AllowedIPs. If it does not, the VPS has no route to 192.0.2.10, and the mount fails with a connection error. The full setup is in routing a WireGuard tunnel to your home LAN.
Over a Tailscale subnet route. A machine at home advertises the LAN, and you approve the route in the admin console:
sudo tailscale set --advertise-routes=192.0.2.0/24Linux clients do not use subnet routes by default, so the VPS must accept them:
sudo tailscale set --accept-routesThe details are in setting up a Tailscale subnet router on a VPS. Two cautions apply to SMB. First, if the tailnet policy file has no acls field, Tailscale treats that as allow-all. You can narrow access with a rule like the one below. This rule is our own example. Tailscale's documentation shows the same shape for a whole subnet. It lets one VPS reach only port 445 on the file server.
{"action": "accept", "src": ["100.100.123.124"], "dst": ["192.0.2.10:445"]}Second, Tailscale has a userspace networking mode, turned on with --tun=userspace-networking. In that mode, apps reach the tailnet through a SOCKS5 or HTTP proxy. The kernel SMB client cannot use such a proxy, so a VPS running in that mode cannot mount a share across the tailnet. Tailscale's page does not mention SMB, so treat this as a conclusion from how the two parts work. A normal VPS install uses the /dev/net/tun device and is not affected.
Whichever tunnel you use, run the port check from the VPS before you mount: nc -vz -w 5 192.0.2.10 445. If the check succeeds, the path is open, and any remaining error is between the client and the SMB server. If it times out, the problem is the route or a firewall, and no mount option will fix it.
FAQ
Why does Ubuntu hang at boot when the network share is offline?
A CIFS line without nofail is required by remote-fs.target, so the boot waits for the mount unit. Add _netdev,nofail,x-systemd.automount to the options. With nofail, the systemd documentation says the boot continues without waiting for the mount unit. With x-systemd.automount, the real mount only starts when something first opens the mount point.
Should I use vers=1.0 to fix a CIFS mount error?
No. vers=1.0 asks for SMB1, which the kernel documentation calls much older and less secure than the default dialect. Windows 11 and Windows Server 2019 and later do not install SMBv1 by default, and Samba's default minimum server protocol is SMB2_02. Find the newest dialect the server supports by trying vers=3.1.1, vers=3.0 and vers=2.1. If the server only offers SMB1, fix or replace the server.
Why are all files on my CIFS mount owned by root?
The server sends no Unix ownership, and the uid= and gid= options both default to 0, which is root. Add uid= and gid= with the values from id -u and id -g, plus file_mode= and dir_mode=. Then unmount and mount again. chown and chmod cannot fix this on a Windows share, because Windows has no CIFS Unix extensions to store the change.
How do I see which SMB version a mount negotiated?
Run findmnt -o TARGET,OPTIONS on the mount point and read the vers= value. In the kernel source, that value comes from the live server connection. It shows the dialect in use even when you mounted with vers=default. sudo cat /proc/fs/cifs/DebugData lists the active sessions and shares if you need more detail.
Is it safe to mount an SMB share from a VPS over the internet?
Not with port 445 open to the internet. Microsoft advises blocking TCP 445 inbound from the internet at the firewall. Connect the VPS to the share's network through WireGuard or a Tailscale subnet route instead. Then run nc -vz -w 5 <server> 445 from the VPS to confirm the port answers through the tunnel.