{"id":487,"date":"2014-12-20T14:53:06","date_gmt":"2014-12-20T19:53:06","guid":{"rendered":"http:\/\/www.virtualroadside.com\/blog\/?p=487"},"modified":"2014-12-20T14:53:06","modified_gmt":"2014-12-20T19:53:06","slug":"simple-python-wrapper-to-give-ssh-a-password-for-automation-purposes-with-output-capture","status":"publish","type":"post","link":"https:\/\/www.virtualroadside.com\/blog\/index.php\/2014\/12\/20\/simple-python-wrapper-to-give-ssh-a-password-for-automation-purposes-with-output-capture\/","title":{"rendered":"Simple python wrapper to give SSH a password for automation purposes (with output capture)"},"content":{"rendered":"<p>A very simple thing that most developers want to do at one time or another is automate SSH. However, since OpenSSH reads the password from the terminal, this can make it a very annoying thing to automate. Indeed, searching google for a solution to this problem yields all sorts of bad answers (and very few good ones).<\/p>\n<p>There are a number of ways to solve the problem in python other than a wrapper around the SSH command:<\/p>\n<ul>\n<li>Use public keys for authentication (this is a generally good practice for this sort of automation, but sometimes you can&#8217;t do this)<\/li>\n<li>Use <a href=\"http:\/\/www.paramiko.org\/\">paramiko<\/a> to talk the SSH protocol directly<\/li>\n<li>Use <a href=\"https:\/\/github.com\/pexpect\/pexpect\">pexpect<\/a>&#8216;s ssh wrapper to wrap openssh instead of rolling your own wrapper<\/li>\n<\/ul>\n<p>However, if you can&#8217;t use external dependencies for some reason, this script is for you. It&#8217;s derived from this <a href=\"http:\/\/blog.clustrix.com\/2012\/01\/31\/scripting-ssh-with-python\/\">script<\/a> and many other sources of information on the net, but I think it&#8217;s a bit simpler to use. It has been tested on Linux and OSX, on Python 2.7 and 3.4. <\/p>\n<p><script src=\"https:\/\/gist.github.com\/virtuald\/54c8657a9ea834fb7fdd.js\"><\/script><\/p>\n<p>Let me know if you have problems with the script!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A very simple thing that most developers want to do at one time or another is automate SSH. However, since OpenSSH reads the password from the terminal, this can make it a very annoying thing to automate. Indeed, searching google for a solution to this problem yields all sorts of bad answers (and very few [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/487"}],"collection":[{"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":3,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/487\/revisions"}],"predecessor-version":[{"id":490,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/487\/revisions\/490"}],"wp:attachment":[{"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtualroadside.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}