{"id":695,"date":"2023-09-03T11:18:06","date_gmt":"2023-09-03T09:18:06","guid":{"rendered":"https:\/\/linux-bibel.at\/?p=695"},"modified":"2023-09-03T11:18:07","modified_gmt":"2023-09-03T09:18:07","slug":"sshpass-ssh-in-scripts-unter-linux-nutzen","status":"publish","type":"post","link":"https:\/\/linux-bibel.at\/index.php\/2023\/09\/03\/sshpass-ssh-in-scripts-unter-linux-nutzen\/","title":{"rendered":"sshpass &#8211; SSH in Scripts unter Linux nutzen"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Nutzt man SSH in Scripts, muss man sich etwas einfallen lassen &#8211; vor allem dann, wenn man etwa auf Ger\u00e4ten arbeitet, auf denen man etwa kein Keyfile ablegen kann &#8211; Hardware-Firewalls etwa.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In diesem Fall m\u00fcsste man das SSH-Passwort angeben, w\u00e4re nat\u00fcrlich m\u00f6glich &#8211; ist aber umst\u00e4ndlich, noch dazu m\u00fcsste man das Passwort im Script angeben. Mit sshpass gelingt dies unter Linux ganz einfach.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">sshpass installieren<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Unter auf Debian basierenden Linux-Distributionen installieren Sie diese Software wie \u00fcblich ganz einfach \u00fcber die\u00a0Paket-Verwaltung\u00a0durch das Paket &#8222;<strong>sshpass<\/strong>&#8222;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">sshpass nutzen<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Nehmen wir einmal an, wir wollen in einem Script den Befehl:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>show status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">auf dem Rechner\u00a0<code>linux-bibel.org<\/code>\u00a0ausf\u00fchren. Grunds\u00e4tzlich k\u00f6nnte man das Passwort\u00a0<code>Passwort<\/code>\u00a0und den Usernamen\u00a0<code>user<\/code>\u00a0im Script angeben:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sshpass -p 'Passwort' ssh user@linux-bibel.org 'show status' &gt; status.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Das Passwort ist im Script sichtbar &#8211; und noch schlimmer, hat man die Systemnachrichten so eingerichtet, dass jeder Benutzer diese sehen kann &#8211; oder die Nachrichten gleich an eine ganze Gruppe per E-Mail versendet &#8211; schlimm. In der E-Mail k\u00f6nnte etwa stehen:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>failed; timeout 'linux-bibel.org': sshpass -p 'Passwort' ssh user@linux-bibel.org 'show status' &gt; status.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Das Passwort ist zwar bei der \u00dcbertragung (<em>per SSH<\/em>) verschl\u00fcsselt, da das Passwort im Befehl steht, ist jedoch in der Nachricht der komplette Befehl sichtbar. Lagert man das Passwort jedoch in eine externe Datei aus, ist auch das Passwort im Befehl nicht zu sehen. Im Beispiel lege ich das Passwort in die Datei &#8222;<strong>dateiname.txt<\/strong>&#8220; aus:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sshpass -fdateiname.txt ssh user@linux-bibel.org 'show status' &gt; status.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In der Datei &#8222;dateiname.txt&#8220; steht anschlie\u00dfend ganz einfach nur in der ersten Zeile das Passwort:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Passwort<\/code><\/pre>\n<div class=\"pld-like-dislike-wrap pld-custom\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir\" data-post-id=\"695\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Hoch.png\" alt=\"Gef\u00e4llt mir\" \/>\r\n            <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"Gef\u00e4llt mir nicht\" data-post-id=\"695\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                            <img src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2023\/12\/Daumen-Runter.png\" alt=\"Gef\u00e4llt mir nicht\" \/>\r\n            <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Nutzt man SSH in Scripts, muss man sich etwas einfallen lassen &#8211; vor allem dann, wenn man etwa auf Ger\u00e4ten arbeitet, auf denen man etwa kein Keyfile ablegen kann &#8211; Hardware-Firewalls etwa. In diesem Fall m\u00fcsste man das SSH-Passwort angeben, w\u00e4re nat\u00fcrlich m\u00f6glich &#8211; ist aber umst\u00e4ndlich, noch dazu m\u00fcsste man das Passwort im Script [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":697,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,61,4],"tags":[12,39,63,7,62,6],"class_list":["post-695","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-netzwerk","category-scripts","category-terminal","tag-kommandozeile","tag-netzwerk","tag-scripts","tag-shell","tag-ssh","tag-terminal"],"_links":{"self":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/comments?post=695"}],"version-history":[{"count":1,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/695\/revisions"}],"predecessor-version":[{"id":698,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/695\/revisions\/698"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media\/697"}],"wp:attachment":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media?parent=695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/categories?post=695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/tags?post=695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}