Use rsa keys for ssh in setup.py install

I am developing a python package that, when installed, should use SSH to communicate with remote servers. I have RSA key validation for all servers that I would like to connect to for my user, but I need to run setup.py with root privileges. Unfortunately, root cannot use the RSA keys I have, so I tried running commands from setup.py with downgraded permissions, but that didn't work. for example, to check if RSA: keys are working after running sudo python

on command line in python environment:

from subprocess import call
call(['ssh','-oBatchMode=yes',host])

      

gives Permission denied (publickey,password).

works only python

on command line and works with the same script works

execute sudo python

at the command line and then:

from subprocess import call
call(['sudo','-u','pi','ssh','-oBatchMode=yes',host])

      

gives the same error

works sudo python

, then:

call(['sudo','-u','pi','whoami'])

      

returns pi

as expected

Why can't I access RSA keys this way? What can I do to make this work?

+3
python linux ssh


source to share


No one has answered this question yet

Check out similar questions:

2683
Check if the given key exists in the dictionary
2453
How do I install pip on Windows?
2369
Add new keys to the dictionary?
1786
Ssh error "permissions too open"
1147
How do I use SSH to run a shell script on a remote machine?
934
How do I specify a private SSH key to use when executing a shell command on Git?
818
Calculate RSA key fingerprint
663
How do I download a file from a server using SSH?
241
Private Key SSH permissions using Git GUI or ssh-keygen too open
174
SSH key: "Permissions 0644 for 'id_rsa.pub' are too open." on mac



All Articles
Loading...
X
Show
Funny
Dev
Pics