简体   繁体   中英

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. 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. How do I do that in Python though? I essentially want the script to end and the terminal to SSH into the machine.

For querying EC2 resources, use the boto library.

For running the ssh, use the subprocess.call (no need to end the script though).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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