Last active
May 24, 2022 12:00
-
-
Save dasgoll/b7af439af1732bbc72f0b7e3109c9952 to your computer and use it in GitHub Desktop.
Paramiko example using private key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import paramiko | |
k = paramiko.RSAKey.from_private_key_file("/Users/goll/.ssh/id_rsa") | |
c = paramiko.SSHClient() | |
c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
print "connecting" | |
c.connect( hostname = "10.10.50.69", username = "goll", pkey = k ) | |
print "connected" | |
commands = [ "sudo /etc/init.d/httpd start" ] | |
#commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ] | |
#commands = [ | |
# "aws s3 cp s3://s3-bucket/scripts/HelloWorld.sh /home/ec2-user/HelloWorld.sh", | |
# "chmod 700 /home/ec2-user/HelloWorld.sh", | |
# "/home/ec2-user/HelloWorld.sh" | |
# ] | |
for command in commands: | |
print "Executing {}".format( command ) | |
stdin , stdout, stderr = c.exec_command(command) | |
print stdout.read() | |
print( "Errors") | |
print stderr.read() | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment