I've a directory mnt with 777 permissions:

drwxrwxrwx 2 root    root   14336 Feb  5 15:52 mnt

I've created a bunch of users in the group root from uid to 5204 to 5250.

I've a python script that launches a bunch of processes which:

  • Change the uid to one of those I created earlier
  • Create a file under mnt directory

but I keep getting IOError: [Errno 13] Permission denied:. What am I missing?

Here's the python script I am using:

from multiprocessing import Process
import random
import time
import os

def test_function(name, uid):
      fname = "/home/username/mnt/file-%s-%d" % (name, random.randrange(100))
      print "Will open file: %s\n" % fname
      file = open(fname, 'w+')

processes = []

for m in range(5204, 5212):
       name = 'Thread-%s' % str(m)
       p = Process(target=test_function, args=(name, m))

for p in processes:

Note: I run this python script with root permissions and mnt is an NFS directory mounted with Amazon EFS

  • Are you sure it's the file creation that is causing the error, and not the call to os.setuid(uid)? – Johan Myréen Feb 5 '17 at 16:44
  • @JohanMyréen yes, I verified that setuid is definitely successful – user1071840 Feb 5 '17 at 16:55
  • can you add the contents of print (os.environ) ? – Michael D. Feb 5 '17 at 17:57
  • {'LANG': 'en_US.UTF-8', 'USERNAME': 'root', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'SUDO_COMMAND': '/usr/bin/python testscript.py', 'HOSTNAME': 'ip-10-1-21-120', 'SUDO_UID': '1311883', 'SUDO_GID': '100', 'HISTSIZE': '1000', 'LOGNAME': 'root', 'USER': 'root', 'PATH': '/sbin:/bin:/usr/sbin:/usr/bin', 'MAIL': '/var/spool/mail/username', 'SUDO_USER': 'username'} – user1071840 Feb 5 '17 at 23:46
  • 1
    Can you create a stackoverflow.com/help/mcve [mcve]? In most cases, just creating [mcve], and thus sorting out the chaff, will point you at the root-cause of your issue. If not, post the [mcve] here, as it'd be easier to help you with it. – boardrider Feb 6 '17 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.