Created
January 9, 2020 23:29
-
-
Save evan-burke/06cdc710483f6e7f76a78d23e73f6d25 to your computer and use it in GitHub Desktop.
ssh with Fabric using an SSH key
This file contains 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
# Fabric can be used to run commands on a remote system over SSH. | |
# Sadly, its docuentation is a bit short for connecting using a private key file. | |
# Other options exist too, like this one using an SSH config file - https://gist.github.com/aubricus/5157931 | |
import fabric | |
# Openssh formatted private key: | |
keyfile = "/path/to/your/privkey" | |
host = "fqdn" | |
user = "myname" | |
with fabric.Connection(host=host, | |
user=user, | |
connect_kwargs={ | |
"key_filename": keyfile | |
} | |
) as sshconn: | |
res = sshconn.run('uname -s') | |
print(res.stdout) | |
# > Linux | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment