Linux 普通用户 mount 报错:mount.cifs: permission denied: no match for
Release Date: Update date: Total Words:289
Reading time: 1m
byAIGC
IP: 上海
Share
Copy Url
A common issue! 😊
When a Linux ordinary user tries to mount a CIFS (Common Internet File System) share using the mount command, they may encounter a “permission denied” error, specifically:
mount.cifs: permission denied: no match for <username> in /etc/samba/smb.conf
This error occurs because the mount command requires root privileges to mount a file system, but the ordinary user doesn’t have the necessary permissions.
To resolve this issue, you have a few options:
- Run the mountcommand withsudo: Prefix themountcommand withsudoto execute it with root privileges. For example:
sudo mount -t cifs //server/share /mnt -o username=<username>,password=<password>
- Add the user to the sudogroup: Add the ordinary user to thesudogroup, which allows them to execute commands with root privileges. You can do this by running the following command as root:
usermod -aG sudo <username>
Then, log out and log back in as the ordinary user to apply the changes.
- Create a fstabentry with user permissions: Create afstabentry with theuseroption, which allows the ordinary user to mount the file system without requiring root privileges. For example, add the following line to/etc/fstab:
//server/share /mnt cifs username=<username>,password=<password>,user 0 0
Then, run mount /mnt as the ordinary user to mount the file system.
- Use a mountwrapper script withsudo: Create a script that wraps themountcommand and runs it withsudoprivileges. For example, create a script calledmount_cifswith the following contents:
#!/bin/bash
sudo mount -t cifs //server/share /mnt -o username=<username>,password=<password>
Make the script executable by running chmod +x mount_cifs, then run the script as the ordinary user: ./mount_cifs
Remember to replace <username>, <password>, //server/share, and /mnt with the actual values for your CIFS share and mount point.
- Prev Page: 脚本解释:loginctl enable-linger $(whoami)
- Next Page: typescript record vs map


