Git authentication as root from Python script doesn't work even when demoted -
i have python script needs run in sudo mode , should run git commands (among them clone , push). these commands can't connect server, because run root , such don't use normal-user ssh key.
so far it's common problem, thing trying demote user before calling these commands. used:
def bash_background_demoted(cmd_list): def _demote(): if getuid() == 0: user = getenv('sudo_user') else: user = getenv('user') uid, gid = pwd.getpwnam(user)[2:4] setegid(gid) seteuid(uid) process = popen(cmd_list, stdout = pipe, stderr = pipe, preexec_fn = _demote) outp, err = process.communicate() print outp + err
this method seems work on other commands, not on git:
bash_background_demoted(['whoami']) # mark bash_background_demoted(['git', 'clone', 'ssh://git@bitbucket.org/stuff', '/repo/dir/']) # permission denied (publickey). # fatal: remote end hung unexpectedly
if don't run sudo, work (but other parts break, it's not acceptable solution).
the -i [keyfile] argument doesn't exist push. know solution? trivial, i'm stuck...
edit: home environment variable set correctly in main process , subprocess. user isn't set correctly, setting doesn't change error.
edit2: i've verified keys causing problem. copies mine /root/.ssh/ , errors went away. not solution though.
(the solution needs work on ubuntu in recent version of python 2)
what home
environment variable set to? make sure points mark
's home , not root
's.
Comments
Post a Comment