Reputation: 562
When executing SCP from subprocess.popen I recieve the error: Warning: Identity File ./id_rsa.key not accessible: no such file or directory.
The problem is explained below.
I want to SCP a file from a local machine to a remote machine, using a python script, and I want to specify the key to use when executing SCP (using -i option).
My local machine is Windows 10 Enterprise. My 'remote' machine is currently a Docker container running Alpine linux on my localhost.
When I run the command in an elevated shell, it works:
scp -i ./id_rsa.key -P 2222 ./test.plan [email protected]:/go/
When I execute the command via Python 3.6 subprocess.popen:
SSH = subprocess.Popen(['scp', '-i ./id_rsa.key', '-P 2222', './test.plan', '[email protected]:/go/'],
cwd = r'C:\ThePathToThisStuff',
shell = False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
It prompts me for a password, [email protected]'s password:
, and when I enter the password it throws the error below, indicating that it fails to find the RSA key:
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'> ERROR: [b'Warning: Identity file ./id_rsa.key not accessible: No such file or directory.\n']
I've tried providing absolute paths to the keys, seperating each command in the arguments list into options and values, different groupings, etc.
Upvotes: 2
Views: 1887
Reputation: 782106
You should not combine an option and its argument in the same parameter, they need to be separate list elements.
SSH = subprocess.Popen(['scp', '-i', './id_rsa.key', '-P', '2222', './test.plan', '[email protected]:/go/'],
Upvotes: 5