Sweety Sweety - 5 days ago 5
Apache Configuration Question

Python CGI script running from web URL creates directory with www-data user

I am trying to run Python CGI script. The issue I am facing is, I need to create a directory and clone repo from git with my username.

#!/usr/bin/python2.7
import commands, os
print "Content-type: text/html\n"
print "\n\n"
print "<html><body>"
commands.getoutput("rm -rf fresh-cloned")
commands.getoutput("mkdir fresh-cloned")
os.chdir("fresh-cloned")
print commands.getoutput("pwd")
commands.getoutput("git clone <> -b <>")


But somehow, when I run the script from web URL : "http://ip_adr/webtest/webgui.py", I see the directory being created with www-data user rather than with my username. Due to that git clone won't work as ssh key is added in Stash for my username only.

drwxr-xr-x 2 www-data www-data 4.0K Nov 28 16:59 fresh-cloned


How can I resolve this issue? Is it possible to change the user to my username while running script from web URL?

Answer

I was able to resolve the issue by changing following line in "/etc/passwd"

www-data:x:33:33:www-data:/var/www:/bin/bash

I created/updated user, gave required permissions, created ssh key and added in stash, it is working now. Thanks!

Comments