简体   繁体   English

用于创建SSH连接的Python脚本

[英]Python script to create SSH connection

I'm trying to write a script that will take a single string (machine name) and use Amazon API to find that machine and get the DNS and SSH into the machine. 我正在尝试编写一个脚本,该脚本将采用单个字符串(计算机名称)并使用Amazon API查找该计算机并将DNS和SSH插入计算机。 If it were a bash script I could simply put in an ssh command and it would create the connection and the user wouldn't notice anything. 如果它是一个bash脚本,我可以简单地放入一个ssh命令,它会创建连接,用户不会注意到任何东西。 How do I do that in Python though? 我怎么用Python做到这一点? I essentially want the script to end and the terminal to SSH into the machine. 我基本上希望脚本结束,终端SSH进入机器。

For querying EC2 resources, use the boto library. 要查询EC2资源,请使用boto库。

For running the ssh, use the subprocess.call (no need to end the script though). 要运行ssh,请使用subprocess.call (尽管不需要结束脚本)。

import subprocess
addr = '10.20.30.40'
subprocess.call([ 'ssh', addr ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM