4

I'm creating a Django app who can access to the user home directory. For this purpose I want to create a directory using something like os.mkdir('/home/user/new_directory') or a subprocess command.

Because Django is started by an apache server, python act as the apache user and can't access to my users home directories.

Currently, I know the login of my users because they have to be logged on the website. Is there a solution to perform unix commands from Django/Python in the name of the user ?

Thibaut Guirimand
  • 851
  • 10
  • 33
  • A user account on the webapp means a different thing from a user on the machine that serves the webapp. There may be even many different machines that serve the same webapp.. – wim Jul 22 '16 at 12:29
  • In my case I use an unified decentralized authentication system between the webapps and the different accessible servers in my network. It's transparent for a unix authentication. – Thibaut Guirimand Jul 22 '16 at 12:57

1 Answers1

0

You can set the home directories via MEDIA_URL /or symlink itself. I think of a combined aproach of symlink and os.system calls.

what-is-symlinking-and-how-can-learn-i-how-to-to-do-this

To change the apache user, use os.system(su <command>) changing-user-in-python

Community
  • 1
  • 1
user2853437
  • 750
  • 8
  • 27
  • This way doesn't really change the user to perform the command. The user is changed during the `os.system()` call only. The whole command with credentials has to be set in during the call : `os.system("echo %s | su %s -c 'bash command' " % (password, username))`. – Thibaut Guirimand Jul 25 '16 at 09:02