{"id":447,"date":"2018-01-25T14:05:25","date_gmt":"2018-01-25T14:05:25","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=447"},"modified":"2018-02-03T16:07:13","modified_gmt":"2018-02-03T16:07:13","slug":"how-to-use-ssh-password-in-a-script","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/how-to-use-ssh-password-in-a-script.html","title":{"rendered":"How To: Use SSH Password in a Script"},"content":{"rendered":"<p>You can obviously use RSA public\/private keypair to access servers without password, although, sometimes, it may be desirable to use ssh password on a command line and run a remote command on another server. This can be done using a tool called &#8216;sshpass&#8217;. You can create a simple bash script using sshpass, that can help you monitor and control multiple servers from a single location.<\/p>\n<h4>How to use ssh password in script<\/h4>\n<p>First install sshpass:<\/p>\n<p><code># yum install sshpass -y<\/code><\/p>\n<p>Once done, you can use sshpass command as following:<\/p>\n<p><code># sshpass -p \"SSH_Password\" ssh -o StrictHostKeyChecking=no SSH_Username@remote-ssh-server \"yourcommand\"<\/code><\/p>\n<p>Just replace, the password, username, remote-ssh-server and your command with your desired setup, and viola!<\/p>\n<p>Note: If yum says, the following:<\/p>\n<p><code>No package sshpass* available.<\/code><\/p>\n<p>then you would need to install epel repository to install sshpass. To install epel, run the following:<\/p>\n<p><code># yum install epel* -y<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can obviously use RSA public\/private keypair to access servers without password, although, sometimes, it may be desirable to use ssh password on a command line and run a remote command on another server. This can be done using a tool called &#8216;sshpass&#8217;. You can create a simple bash script using sshpass, that can help &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/how-to-use-ssh-password-in-a-script.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To: Use SSH Password in a Script&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[282,180,12,271,191,21,150,25,192],"tags":[283,276,288,289],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/447"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":3,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"predecessor-version":[{"id":453,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/447\/revisions\/453"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}