{"id":76,"date":"2009-02-13T15:17:11","date_gmt":"2009-02-13T22:17:11","guid":{"rendered":"http:\/\/www.zulutown.com\/blog\/?p=76"},"modified":"2009-02-13T15:17:11","modified_gmt":"2009-02-13T22:17:11","slug":"executing-commands-and-scripts-remotely-with-ssh","status":"publish","type":"post","link":"https:\/\/www.zulutown.com\/blog\/2009\/02\/13\/executing-commands-and-scripts-remotely-with-ssh\/","title":{"rendered":"Executing Commands and Scripts Remotely with ssh"},"content":{"rendered":"<p>Often it&#8217;s required to execute on a remote server a command or a whole bash script.<br \/>\nNot everyone knows that through <code>ssh<\/code> it&#8217;s possible to execute this task.<\/p>\n<p>Here&#8217;s the ssh syntax:<\/p>\n<pre>usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]\r\n           [-D [bind_address:]port] [-e escape_char] [-F configfile]\r\n           [-i identity_file] [-L [bind_address:]port:host:hostport]\r\n           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\r\n           [-R [bind_address:]port:host:hostport] [-S ctl_path]\r\n           [-w local_tun[:remote_tun]] [user@]hostname [command]<\/pre>\n<p>In the following example , the <code>ls<\/code> command is run on the remote server.<\/p>\n<pre>ssh remoteuser@remoteserver.com ls<\/pre>\n<p>To run a local script on the remote server, it&#8217;s required to upload it (through <code>scp<\/code>), set it as executable and finally run it.<\/p>\n<p>The related example:<\/p>\n<pre>scp myscript.sh remoteuser@remoteserver.com:\/remotedir\/myscript.sh\r\nssh remoteuser@remoteserver.com \"chmod +x \/remotedir\/myscript.sh\"\r\nssh remoteuser@remoteserver.com \/remotedir\/myscript.sh<\/pre>\n<p>Of course it&#8217;s required to type the password after each command (or to use a identity key file)<\/p>\n<p>Looking through the <code>ssh<\/code> options it&#8217;s possible to find many other feature offered by this common command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often it&#8217;s required to execute on a remote server a command or a whole bash script. Not everyone knows that through ssh it&#8217;s possible to execute this task. Here&#8217;s the ssh syntax: usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D &hellip; <a href=\"https:\/\/www.zulutown.com\/blog\/2009\/02\/13\/executing-commands-and-scripts-remotely-with-ssh\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,27],"tags":[38,37,39,30],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-linux-unix","category-system-administration","tag-command","tag-remotely","tag-script","tag-ssh"],"_links":{"self":[{"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":1,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":77,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/posts\/76\/revisions\/77"}],"wp:attachment":[{"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zulutown.com\/blog\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}