Linux 普通用户 mount 报错:mount.cifs: permission denied: no match for

Release Date: Update date: Total Words: 289 Reading time: 1m by 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:

  1. Run the mount command with sudo: Prefix the mount command with sudo to execute it with root privileges. For example:
sudo mount -t cifs //server/share /mnt -o username=<username>,password=<password>
  1. Add the user to the sudo group: Add the ordinary user to the sudo group, 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.

  1. Create a fstab entry with user permissions: Create a fstab entry with the user option, 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.

  1. Use a mount wrapper script with sudo: Create a script that wraps the mount command and runs it with sudo privileges. For example, create a script called mount_cifs with 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.

Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数