双系统环境下Ubuntu访问HDD中C/C++文件提示Permission Denied的解决请求
Hey there, let's work through this permission issue step by step. The main problem here is almost definitely how your NTFS-formatted HDD is mounted in Ubuntu—Windows handles file permissions totally differently, so Ubuntu doesn't automatically recognize the execution rights you might have set up in Windows. Here's how to fix it:
临时快速修复(单次生效,重启后失效)
First, find where your HDD is mounted. You can check this via the file manager—it's usually in /media/[your-username]/[drive-name] (like /media/saied/Storage) or under /mnt. Once you have the path:
- Unmount the drive first in the terminal:
sudo umount /media/saied/Storage - Remount it with permissions that allow execution:
sudo mount -t ntfs-3g -o uid=$UID,gid=$GID,umask=0022 /dev/sdXn /media/saied/Storage- Replace
/dev/sdXnwith your HDD's partition identifier (uselsblkin terminal to find this—look for the 1TB drive, it might be something like/dev/sdb1). - The
umask=0022setting ensures you (the owner) have read/write/execute access, while other users get read/execute rights—perfect for running your compiled C/C++ files.
- Replace
永久解决方法(开机自动应用权限)
The above fix will reset after a reboot, so let's set it to stick permanently by editing the fstab file:
- Get your HDD partition's UUID (a unique identifier that won't change even if drive letters shift):
Look for the line corresponding to your NTFS storage drive, then copy theblkidUUID="xxxx-xxxx"part. - Open the
fstabfile for editing:sudo nano /etc/fstab - Paste this line at the end of the file, replacing the UUID and mount path with your own:
UUID=xxxx-xxxx /media/saied/Storage ntfs-3g uid=$UID,gid=$GID,umask=0022 0 0 - Save and exit: Press
Ctrl+O, hit Enter to confirm, thenCtrl+Xto close nano. - Test the setup to make sure there are no errors:
If you don't see any error messages, you're good to go—your HDD will now mount with the correct permissions every time you boot Ubuntu.sudo mount -a
Extra Tip: Ensure Your Executable Has Run Permissions
If you're trying to run a compiled C/C++ binary, even with the correct mount permissions, you might need to explicitly grant execution rights to the file itself:
chmod +x /path/to/your/compiled_program
This tells Ubuntu that the file is allowed to be executed as a program.
备注:内容来源于stack exchange,提问作者Md Saiedur Rahman Saied

