我正在使用Genymotion on demand aws实例,并尝试从python连接它。我想从python向实例发送adb命令。此处提供了从任意计算机连接实例的教程:https://www.genymotion.com/help/on-demand/tutorial/enable-disable-adb/
为实例创建ssh通道的ssh命令为:
ssh -i key.pem -NL 5555:localhost:5555 root@instance_ip
我尝试使用paramiko库和他们的存储库(https://github.com/paramiko/paramiko/blob/master/demos/forward.py)中的forward.py演示。
首先,我尝试通过cli创建隧道,这是我在创建ssh隧道时输入的内容:
python forward.py <instance_ip> -r localhost:5555 -u root -p 5555 -K "path/to/mykey.pem"
得到的回应是:
Connecting to ssh host <instance_ip>:22 ...
*** Failed to connect to <instance_ip>:22: EOFError()
我不知道这里有什么问题。
有人能帮帮我吗?非常感谢!
发布于 2017-03-09 14:01:18
您可以使用以下代码片段从Python ssh到EC2实例。
key = paramiko.RSAKey.from_private_key_file(path/to/mykey.pem)
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect/ssh to an instance
try:
client.connect(hostname=instance_ip, username="root", pkey=key)
# Execute a command(cmd) after connecting/ssh to an instance
stdin, stdout, stderr = client.exec_command(cmd)
print stdout.read()
# close the client connection once the job is done
client.close()
break
except Exception, e:
print e
https://stackoverflow.com/questions/42672998
复制相似问题