You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

双系统环境下Ubuntu访问HDD中C/C++文件提示Permission Denied的解决请求

双系统环境下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:

  1. Unmount the drive first in the terminal:
    sudo umount /media/saied/Storage
    
  2. 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/sdXn with your HDD's partition identifier (use lsblk in terminal to find this—look for the 1TB drive, it might be something like /dev/sdb1).
    • The umask=0022 setting ensures you (the owner) have read/write/execute access, while other users get read/execute rights—perfect for running your compiled C/C++ files.

永久解决方法(开机自动应用权限)

The above fix will reset after a reboot, so let's set it to stick permanently by editing the fstab file:

  1. Get your HDD partition's UUID (a unique identifier that won't change even if drive letters shift):
    blkid
    
    Look for the line corresponding to your NTFS storage drive, then copy the UUID="xxxx-xxxx" part.
  2. Open the fstab file for editing:
    sudo nano /etc/fstab
    
  3. 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
    
  4. Save and exit: Press Ctrl+O, hit Enter to confirm, then Ctrl+X to close nano.
  5. Test the setup to make sure there are no errors:
    sudo mount -a
    
    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.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 10:24:06