<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2014:11:23</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Thu, 30 Apr 2026 04:57:29 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>openssh_and_command_line_passwords</title>
            <link>https://baszerr.eu/doku.php?id=blog:2014:11:23:openssh_and_command_line_passwords</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;openssh_and_command_line_passwords&quot;&gt;2014-11-23 - openssh and command line passwords&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2014%3A11%3A23%3Aopenssh_and_command_line_passwords&amp;amp;media=blog:2014:11:23:openssh_logo.png&quot; class=&quot;media&quot; title=&quot;blog:2014:11:23:openssh_logo.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2014:11:23:openssh_logo.png&quot; class=&quot;mediaright&quot; align=&quot;right&quot; loading=&quot;lazy&quot; title=&quot;OpenSSH logo&quot; alt=&quot;OpenSSH logo&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://en.wikipedia.org/wiki/openssh&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/openssh&quot;&gt;openssh&lt;/a&gt; does not permit you to give password in a plain text, from the command line or simple pipe from terminal. generally this is a good idea, as it makes it difficult to make system less secure. if you were to use password-less login, using keys is the way. there is an exception to the rule. there are cases, when you cannot use keys nor you are allowed to change password and the system is just some development machine, not connected to an internal network, to which everyone in the company knows password… but no1 can remember it. if you happen to hit this type of situation you know how difficult it is to automate work.
&lt;/p&gt;

&lt;p&gt;
fortunately it can be easily solved with tool called &lt;em&gt;sshpass&lt;/em&gt; (just do &lt;em&gt;apt-get install sshpass&lt;/em&gt; to get there).
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2014-11-23 - openssh and command line passwords&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;openssh_and_command_line_passwords&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-873&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;just_like_that&quot;&gt;just like that...&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
with &lt;em&gt;sshpass&lt;/em&gt; you can just type in the password from the command line like this:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;sshpass &lt;span class=&quot;re5&quot;&gt;-p&lt;/span&gt; dumasspassword &lt;span class=&quot;kw2&quot;&gt;ssh&lt;/span&gt; user&lt;span class=&quot;sy0&quot;&gt;@&lt;/span&gt;machine &lt;span class=&quot;kw3&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-arg1&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-arg2&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
and you&amp;#039;re done. this is usually not so good idea, but this is possible. you can even put this inside the script if you dare…
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;just like that...&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;just_like_that&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;874-1203&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;more_secure_version&quot;&gt;more secure version&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
however there might be another situation. even though system i restrictive when it comes to keys/passwords policies, users might still have some level of security. for instance others should not be able to see their password with simple &lt;em&gt;ps -axlf&lt;/em&gt;. one might want to do this, when script needs to run multiple commands on remote machine, in some time span, but under a single execution.
&lt;/p&gt;

&lt;p&gt;
&lt;em&gt;sshpass&lt;/em&gt; allows to make this more secure with reading password from file descriptor:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;re2&quot;&gt;REMOTE_USER&lt;/span&gt;=&lt;span class=&quot;st0&quot;&gt;&amp;quot;you&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;HOST&lt;/span&gt;=&lt;span class=&quot;st0&quot;&gt;&amp;quot;there&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;read&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;password for &lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;: &amp;quot;&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-s&lt;/span&gt; PASS
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw3&quot;&gt;exec&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$PASS&lt;/span&gt;&amp;quot;&lt;/span&gt;
sshpass &lt;span class=&quot;re5&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;ssh&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-Y&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;&amp;quot;&lt;/span&gt; command1
&amp;nbsp;
&lt;span class=&quot;kw3&quot;&gt;exec&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$PASS&lt;/span&gt;&amp;quot;&lt;/span&gt;             
sshpass &lt;span class=&quot;re5&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;ssh&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-Y&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;&amp;quot;&lt;/span&gt; command2&lt;/pre&gt;

&lt;p&gt;
now user can type in password once and reuse it in multiple commands. i have used this approach to automate work in few development environments. users can pass their password, without others knowing it (assuming no1 is tempering with the script itself ;)). it is verbose though, as file descriptor (here: 42) needs to be refreshed each time sshpass is to be used.
&lt;/p&gt;

&lt;p&gt;
fortunately there is even simpler way to go – export &lt;em&gt;SSHPASS&lt;/em&gt; variable with a password and pass &lt;em&gt;-e&lt;/em&gt; to &lt;em&gt;sshpass&lt;/em&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;re2&quot;&gt;REMOTE_USER&lt;/span&gt;=&lt;span class=&quot;st0&quot;&gt;&amp;quot;you&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;HOST&lt;/span&gt;=&lt;span class=&quot;st0&quot;&gt;&amp;quot;there&amp;quot;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;read&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;password for &lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;: &amp;quot;&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-s&lt;/span&gt; SSHPASS
&lt;span class=&quot;kw3&quot;&gt;export&lt;/span&gt; SSHPASS
&lt;span class=&quot;kw3&quot;&gt;echo&lt;/span&gt;
sshpass &lt;span class=&quot;re5&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;ssh&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-Y&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;&amp;quot;&lt;/span&gt; command1
sshpass &lt;span class=&quot;re5&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;ssh&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-Y&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$REMOTE_USER&lt;/span&gt;@&lt;span class=&quot;es2&quot;&gt;$HOST&lt;/span&gt;&amp;quot;&lt;/span&gt; command2&lt;/pre&gt;

&lt;p&gt;
have fun scripting the universe. ;)
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;more secure version&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;more_secure_version&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1204-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:08:53 +0000</pubDate>
        </item>
    </channel>
</rss>
