Dealing with Windows shares containing spaces in their paths has been a long-standing pain point for Linux administrators. The fundamental issue stems from how Unix-like systems traditionally handle whitespace in filesystem operations versus Windows conventions.
The cryptic CIFS VFS: cifs_mount failed w/return code = -22
typically indicates an invalid argument was passed to the mount command. When spaces are involved, this usually means the path parsing failed before reaching the authentication stage.
After extensive testing across Debian-based systems, the most reliable approach is to:
//servername.org.au/ABC/Company\040Services/Department\040Services/Area\040Services/Restricted /mnt/n-drive cifs credentials=/etc/samba/login.crt,iocharset=utf8,sec=ntlmssp 0 0
- Use
\040
(octal for space) for EACH space character - Ensure no quotes are used in the UNC path
- Add
sec=ntlmssp
for modern Windows servers - Consider using IP instead of hostname if DNS resolution is flaky
For systems where credential files aren't preferred:
//192.168.1.100/ABC/Company\040Services/Department\040Services/Area\040Services/Restricted /mnt/n-drive cifs username=winuser,password=winpass,iocharset=utf8,uid=1000,gid=1000 0 0
When troubleshooting stubborn cases:
# Test basic connectivity
smbclient -L //servername -U username
# Manual mount test
sudo mount -t cifs "//servername/ABC/Company Services/Department Services" /mnt/test -o credentials=/etc/samba/login.crt
# Check kernel messages
dmesg | grep CIFS
For extremely problematic paths, consider:
- Creating a symbolic link on the Windows server to a simpler path
- Using autofs with simpler mount points
- Mounting via script using the
mount.cifs
command
When dealing with Windows shares containing spaces in their path names, Linux systems can throw cryptic errors like CIFS VFS: cifs_mount failed w/return code = -22
. Here's how we can crack this case.
The standard approaches you've tried (quotes, \040, backslashes) don't work because of how the CIFS implementation processes the mount path before kernel handling. The issue stems from multiple layers of parsing:
- fstab parsing
- CIFS client processing
- Kernel path handling
For CIFS mounts with spaces, we need to use UNC encoding with URI-style escaping:
//servername.org.au/ABC/Company%20Services/Department%20Services/Area%20Services/Restricted /mnt/n-drive cifs credentials=/etc/samba/login.crt,uid=0,iocharset=utf8,noperm 0 0
Key points about this solution:
- %20 is the URL encoding for space character
- No quotes or backslashes needed
- Works with both IPv4 and hostnames
If you prefer testing before adding to fstab, use the mount command with proper escaping:
sudo mount -t cifs "//servername.org.au/ABC/Company Services/Department Services/Area Services/Restricted" /mnt/n-drive -o credentials=/etc/samba/login.crt,uid=0,iocharset=utf8,noperm
When things still don't work:
- Check share accessibility:
smbclient -L servername.org.au -U username
- Test credentials:
smbclient //servername.org.au/ABC -U username
- Enable debug: add
debug
to mount options
For optimal performance with complex paths:
//server/path /mountpoint cifs credentials=file,uid=0,gid=0,file_mode=0644,dir_mode=0755,cache=strict,actimeo=120 0 0
Remember that each additional directory level in the path may impact lookup performance.
When dealing with sensitive shares:
- Always use credential files with 600 permissions
- Consider using krb5 authentication if available
- Avoid world-readable mount points
For modern systems, consider using systemd mount units:
[Unit]
Description=Mount Company Services Share
[Mount]
What=//servername.org.au/ABC/Company%20Services/Department%20Services/Area%20Services/Restricted
Where=/mnt/n-drive
Type=cifs
Options=credentials=/etc/samba/login.crt,uid=0,iocharset=utf8,noperm
[Install]
WantedBy=multi-user.target
This approach provides better dependency handling and more readable configuration.