mkdir 权限被拒绝

Pop*_*orn 5 python unix permissions mkdir

我试图/var/machine/hi'通过在 Python 中运行它来创建这个目录:

os.mkdir("/var/machine/hi")
Run Code Online (Sandbox Code Playgroud)

但是,我得到了一个

OSError: [Errno 13] Permission denied: '/var/machine/hi'
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法: chmod 777 /var/machinechmod 777 /var

业主为/varISroot wheel

业主为/var/machineISroot wheel

我该如何修复/调试这个?

sir*_*ine 6

您是否尝试过仅对操作使用 os.system 和 sudo 命令?

os.system("sudo mkdir /var/machine/hi")
Run Code Online (Sandbox Code Playgroud)


mu *_*u 無 0

/var 的所有者是根轮

/var/machine 的所有者是 rootwheel

您尝试在其中创建目录的目录的所有者是root,因此,您必须以root或 as运行sudo

或者,您可以使用以下命令更改目录用户所有权

sudo chown popcorn:wheel /var/machine
Run Code Online (Sandbox Code Playgroud)

但这假设用户爆米花已添加到wheel