mkdir permission denied

Popcorn picture Popcorn · Sep 30, 2013 · Viewed 16.5k times · Source

I'm trying to make this directory /var/machine/hi' by running this in Python:

os.mkdir("/var/machine/hi")

However, I'm getting a

OSError: [Errno 13] Permission denied: '/var/machine/hi'

I have tried the following: chmod 777 /var/machine and chmod 777 /var

The owners for /var is root wheel

The owners for /var/machine is root wheel

How can I fix/debug this?

Answer

sirFunkenstine picture sirFunkenstine · Mar 19, 2015

Have you tried using os.system with a sudo command on the operation only?

os.system("sudo mkdir /var/machine/hi")