Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python script to create SSH connection

Tags:

python

ssh

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.

like image 800
tbeauvais Avatar asked May 13 '26 13:05

tbeauvais


1 Answers

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 ])
like image 174


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!