2016-03-28 7 views
1

でサブプロセスを使用してSSHすることができません:私は、次のコマンドを使用してPythonのサブプロセスを使用してSSHしようとしているIDファイル

subprocess.Popen(["ssh", "-i %s/.ssh/anotherIdentity" % os.path.expanduser("~"), " [email protected]%s" % host, command], 
shell=False, 
stdout=subprocess.PIPE, 
stderr=subprocess.PIPE) 

私はエラーを取得しています:

['Warning: Identity file /Users/saurabh.araiyer/.ssh/anotherIdentity not accessible: No such file or directory.\n', 'Permission denied (publickey). 

アイデンティティファイルが存在していますその場所に、 これの背後にある理由は何でしょうか?

Pythonのバージョン:2.7.10マック

答えて

2

では、我々は-i後に余分なスペースを削除した場合ので、それは動作します

subprocess.Popen(["ssh", "-i %s/.ssh/anotherIdentity" % os.path.expanduser("~"), " [email protected]%s" % host, command], 

でここに余分なスペースがあります。正しい使用方法:

subprocess.Popen(["ssh", "-i%s/.ssh/anotherIdentity" % os.path.expanduser("~"), " [email protected]%s" % host, command], 

または異なるパラメータ

subprocess.Popen(["ssh", "-i", "%s/.ssh/anotherIdentity" % os.path.expanduser("~"), " [email protected]%s" % host, command], 
-iと引数を分離
関連する問題