<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>ssh &amp;mdash; alan</title>
    <link>https://www.franzoni.eu/alan/tag:ssh</link>
    <description>Alan&#39;s musings</description>
    <language>en</language>
    <pubDate>Tue, 17 Nov 2026 00:40:53 +0000</pubDate>
    <item>
      <title>SCP taming: stop local silliness</title>
      <link>https://www.franzoni.eu/alan/scp-taming-stop-local-sillyness</link>
      <description>&lt;![CDATA[Every day now and then, I get an scp command wrong. Scp is designed after commands like rcp and works totally fine for local-to-local file copy.&#xA;&#xA;While this can (or could) be useful in some contexts, It&#39;s not what I like to do these days; very often, if either hosts is not remote, it&#39;s a typo on my part, and results in spurious &#34;somebody@host.example.com&#34; files somewhere in various directories on my disk.&#xA;&#xA;So, what I like to do? I put a small script like this in my path before the actual scp executable in order to pre-check arguments, and prevent accidental local-only copies.&#xA;&#xA;!/bin/bash&#xA;ORIG=&#34;/usr/bin/scp&#34;&#xA;&#xA;for var in &#34;$@&#34;&#xA;do&#xA;    if [[ $var = &#34;:&#34; ]]; then&#xA;        $ORIG &#34;$@&#34;&#xA;        exit $?&#xA;    fi&#xA;done&#xA;&#xA;echo &#34;ERROR: Missing colon. You need to pass at least one remote host specifier in source or dest&#34;&#xA;exit 1&#xA;&#xA;#MostlyUnixish #ssh #scp&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Every <del>day</del> now and then, I get an <strong>scp</strong> command wrong. Scp is designed after commands like <a href="https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.cmds4/rcp.htm" rel="nofollow">rcp</a> and works totally fine for local-to-local file copy.</p>

<p>While this can (or could) be useful in some contexts, It&#39;s not what I like to do these days; very often, if either hosts is not remote, it&#39;s a typo on my part, and results in spurious “<a href="mailto:somebody@host.example.com" rel="nofollow">somebody@host.example.com</a>” files somewhere in various directories on my disk.</p>

<p>So, what I like to do? I put a small script like this in my path <em>before</em> the actual scp executable in order to pre-check arguments, and prevent accidental local-only copies.</p>

<pre><code class="language-bash">#!/bin/bash
ORIG=&#34;/usr/bin/scp&#34;

for var in &#34;$@&#34;
do
    if [[ $var = *&#34;:&#34;* ]]; then
        $ORIG &#34;$@&#34;
        exit $?
    fi
done

echo &#34;ERROR: Missing colon. You need to pass at least one remote host specifier in source or dest&#34;
exit 1
</code></pre>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:ssh" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ssh</span></a> <a href="/alan/tag:scp" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">scp</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/scp-taming-stop-local-sillyness</guid>
      <pubDate>Thu, 26 Apr 2018 10:38:49 +0000</pubDate>
    </item>
    <item>
      <title>SSH hostnames configuration and shortcuts</title>
      <link>https://www.franzoni.eu/alan/ssh-hostnames-configuration-and-shortcuts</link>
      <description>&lt;![CDATA[This is another old trick, but I like to tell the world about such amenities.&#xA;&#xA;I often find people writing command lines such as:&#xA;&#xA;ssh arcane-system-user@someextremelylong.andimpossibiletotype.anderrorprone.hostname.com&#xA;&#xA;or, worse&#xA;&#xA;ssh idliketorememberwhichuser@10.20.30.40&#xA;&#xA;or maybe it was&#xA;&#xA;ssh someuserimashamedof@1.2.3.4&#xA;&#xA;yes, sometimes ssh is simply tedious.&#xA;&#xA;But you can do better. In fact, you can do much better.&#xA;&#xA;your ~/.ssh/config or /etc/ssh/ssh\_config can contain Host configuration sections; I have already blogged about such directives when I told the world about stopping key verification compliants - they&#39;re very flexible, indeed.&#xA;&#xA;Consider adding Host directives in your configuration for your most used services:&#xA;&#xA;Host myniceserver&#xA;    Hostname myniceserver.mylove.com&#xA;    Port 12345&#xA;    User teddybear&#xA;&#xA;And then you can just&#xA;&#xA;ssh myniceserver&#xA;&#xA;You can override most options on a per-server basis and/or select a certain private key for connections.&#xA;&#xA;#MostlyUnixish #linux #ssh #ancientwisdom&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>This is another old trick, but I like to tell the world about such amenities.</p>

<p>I often find people writing command lines such as:</p>

<pre><code>ssh arcane-system-user@someextremelylong.andimpossibiletotype.anderrorprone.hostname.com
</code></pre>

<p>or, worse</p>

<pre><code>ssh idliketorememberwhichuser@10.20.30.40
</code></pre>

<p>or maybe it was</p>

<pre><code>ssh someuserimashamedof@1.2.3.4
</code></pre>

<p>yes, sometimes ssh is simply tedious.</p>

<p>But you can do better. In fact, you can do <strong>much</strong> better.</p>

<p>your <em>~/.ssh/config</em> or <em>/etc/ssh/ssh_config</em> can contain <strong>Host</strong> configuration sections; I have already blogged about such directives when I told the world about stopping <a href="/alan/ssh-client-stopping-key-verification-complaints-inside-your-own-private-network" rel="nofollow">key verification compliants</a> – they&#39;re very flexible, indeed.</p>

<p>Consider adding <strong>Host</strong> directives in your configuration for your most used services:</p>

<pre><code>Host myniceserver
    Hostname myniceserver.mylove.com
    Port 12345
    User teddybear
</code></pre>

<p>And then you can just</p>

<pre><code>ssh myniceserver
</code></pre>

<p>You can override most options on a per-server basis and/or select a certain private key for connections.</p>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:linux" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linux</span></a> <a href="/alan/tag:ssh" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ssh</span></a> <a href="/alan/tag:ancientwisdom" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ancientwisdom</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/ssh-hostnames-configuration-and-shortcuts</guid>
      <pubDate>Wed, 10 Dec 2014 22:24:00 +0000</pubDate>
    </item>
    <item>
      <title>ssh-copy-id with nonstandard sshd port</title>
      <link>https://www.franzoni.eu/alan/ssh-copy-id-with-nonstandard-sshd-port</link>
      <description>&lt;![CDATA[UPDATE: modern ssh-copy-id often support a -p parameter for the port. So this trick is unnecessary and won&#39;t probably work.&#xA;&#xA;ssh-copy-id is a cool script which is usually distributed along openssh client nowadays;&#xA;it performs an automatic install of your local public SSH key to a remote server. Its syntax is simply:&#xA;&#xA;ssh-copy-id [-i [identityfile]] [user@]machine&#xA;&#xA;You may have spotted there&#39;s no builtin way of telling it what&#39;s the port of the remote server; a workaround exists which leverages&#xA;the way arguments are passed to the script (it&#39;s a simple bash file, take a look at it. You can find various versions around the internet).&#xA;&#xA;Just do this:&#xA;&#xA;ssh-copy-id &#39;-p [portnumber] [-i [identity_file]] [user@]machine&#39;&#xA;&#xA;And enjoy your newly-added SSH key!&#xA;&#xA;#MostlyUnixish #ssh&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<ul><li><strong>UPDATE:</strong> modern ssh-copy-id often support a -p parameter for the port. So this trick is unnecessary and won&#39;t probably work.</li></ul>

<p><a href="http://linux.die.net/man/1/ssh-copy-id" rel="nofollow">ssh-copy-id</a> is a cool script which is usually distributed along openssh client nowadays;
it performs an automatic install of your local public SSH key to a remote server. Its syntax is simply:</p>

<p><code>ssh-copy-id [-i [identity_file]] [user@]machine</code></p>

<p>You may have spotted there&#39;s no builtin way of telling it what&#39;s the port of the remote server; a workaround exists which leverages
the way arguments are passed to the script (it&#39;s a simple bash file, take a look at it. You can find various versions around <a href="https://gist.github.com/378862" rel="nofollow">the internet</a>).</p>

<p>Just do this:</p>

<p><code>ssh-copy-id &#39;-p [port_number] [-i [identity_file]] [user@]machine&#39;</code></p>

<p>And enjoy your newly-added SSH key!</p>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:ssh" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ssh</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/ssh-copy-id-with-nonstandard-sshd-port</guid>
      <pubDate>Tue, 06 Nov 2012 21:41:00 +0000</pubDate>
    </item>
    <item>
      <title>ssh client: stopping key verification complaints inside your own private network</title>
      <link>https://www.franzoni.eu/alan/ssh-client-stopping-key-verification-complaints-inside-your-own-private-network</link>
      <description>&lt;![CDATA[If you develop enough software, most probably you&#39;ll have a test/development network at your service.&#xA;&#xA;In such networks, which are usually handled through a virtualization infrastructure, machines come and go very quickly.&#xA;But ssh clients are usually unhappy about that:&#xA;&#xA;alan@melquiades:/etc/ssh$ ssh root@192.168.0.208&#xA;The authenticity of host &#39;192.168.0.208 (192.168.0.208)&#39; can&#39;t be established.&#xA;RSA key fingerprint is 31:4d:8b:97:c8:57:04:85:6a:1b:72:54:46:ab:04:bc.&#xA;Are you sure you want to continue connecting (yes/no)? yes&#xA;Warning: Permanently added &#39;192.168.0.208&#39; (RSA) to the list of known hosts.&#xA;root@192.168.0.208&#39;s password: &#xA;&#xA;The first time you connect, you&#39;re asked if the fingerprint is correct. The second time you&#39;ll just be allowed to connect:&#xA;&#xA;alan@melquiades:/etc/ssh$ ssh root@192.168.0.208&#xA;root@192.168.0.208&#39;s password: &#xA;&#xA;What then if the machine at such ip address changes, because it&#39;s rebuilt or modified and the ssh host key is not retained?&#xA;&#xA;alan@melquiades:/etc/ssh$ ssh root@192.168.0.208&#xA;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&#xA;@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @&#xA;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&#xA;IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!&#xA;Someone could be eavesdropping on you right now (man-in-the-middle attack)!&#xA;It is also possible that a host key has just been changed.&#xA;The fingerprint for the RSA key sent by the remote host is&#xA;7b:42:03:5f:5c:8d:5a:2b:6a:a4:1e:d6:0d:05:de:38.&#xA;Please contact your system administrator.&#xA;Add correct host key in /Users/alan/.ssh/knownhosts to get rid of this message.&#xA;Offending RSA key in /Users/alan/.ssh/knownhosts:111&#xA;  remove with: ssh-keygen -f &#34;/Users/alan/.ssh/knownhosts&#34; -R 192.168.0.208&#xA;RSA host key for 192.168.0.208 has changed and you have requested strict checking.&#xA;Host key verification failed.&#xA;&#xA;From the point of view of openssh this may be a serious security breach, and you should fear such message if it happens in the wild if you haven&#39;t touched a server -&#xA;a MitM attack is probably going on!&#xA;&#xA;What about your local network? ssh-keygen -R 192.168.0.208 will solve that, but you probably didn&#39;t need host key authentication since the beginning.&#xA;&#xA;So, just add this:&#xA;&#xA;Host 192.168.0.*&#xA;    CheckHostIP no&#xA;    UserKnownHostsFile /dev/null&#xA;    StrictHostKeyChecking no&#xA;&#xA;at the beginning of your /etc/ssh/sshconfig file, and feel good.&#xA;&#xA;Now, anytime you try connecting inside your network you&#39;ll be greeted by this:&#xA;&#xA;alan@melquiades:/etc/ssh$ ssh root@192.168.0.208&#xA;Warning: Permanently added &#39;192.168.0.208&#39; (RSA) to the list of known hosts.&#xA;root@192.168.0.208&#39;s password: &#xA;&#xA;No confirmations whatsoever.&#xA;&#xA;#MostlyUnixish #linux #ssh&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>If you develop enough software, most probably you&#39;ll have a test/development network at your service.</p>

<p>In such networks, which are usually handled through a virtualization infrastructure, machines come and go very quickly.
But ssh clients are usually unhappy about that:</p>

<pre><code>alan@melquiades:/etc/ssh$ ssh root@192.168.0.208
The authenticity of host &#39;192.168.0.208 (192.168.0.208)&#39; can&#39;t be established.
RSA key fingerprint is 31:4d:8b:97:c8:57:04:85:6a:1b:72:54:46:ab:04:bc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added &#39;192.168.0.208&#39; (RSA) to the list of known hosts.
root@192.168.0.208&#39;s password: 
</code></pre>

<p>The first time you connect, you&#39;re asked if the fingerprint is correct. The second time you&#39;ll just be allowed to connect:</p>

<pre><code>alan@melquiades:/etc/ssh$ ssh root@192.168.0.208
root@192.168.0.208&#39;s password: 
</code></pre>

<p>What then if the machine at such ip address changes, because it&#39;s rebuilt or modified and the ssh host key is not retained?</p>

<pre><code>alan@melquiades:/etc/ssh$ ssh root@192.168.0.208
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
7b:42:03:5f:5c:8d:5a:2b:6a:a4:1e:d6:0d:05:de:38.
Please contact your system administrator.
Add correct host key in /Users/alan/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/alan/.ssh/known_hosts:111
  remove with: ssh-keygen -f &#34;/Users/alan/.ssh/known_hosts&#34; -R 192.168.0.208
RSA host key for 192.168.0.208 has changed and you have requested strict checking.
Host key verification failed.
</code></pre>

<p>From the point of view of openssh this may be a serious security breach, and you should fear such message if it happens in the wild if you haven&#39;t touched a server -
a MitM attack is probably going on!</p>

<p>What about your local network? <code>ssh-keygen -R 192.168.0.208</code> will solve that, but you probably didn&#39;t need host key authentication since the beginning.</p>

<p>So, just add this:</p>

<pre><code>Host 192.168.0.*
    CheckHostIP no
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
</code></pre>

<p>at the beginning of your <code>/etc/ssh/ssh_config</code> file, and feel good.</p>

<p>Now, anytime you try connecting inside your network you&#39;ll be greeted by this:</p>

<pre><code>alan@melquiades:/etc/ssh$ ssh root@192.168.0.208
Warning: Permanently added &#39;192.168.0.208&#39; (RSA) to the list of known hosts.
root@192.168.0.208&#39;s password: 
</code></pre>

<p>No confirmations whatsoever.</p>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:linux" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linux</span></a> <a href="/alan/tag:ssh" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ssh</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/ssh-client-stopping-key-verification-complaints-inside-your-own-private-network</guid>
      <pubDate>Sun, 26 Aug 2012 20:39:00 +0000</pubDate>
    </item>
    <item>
      <title>Disown is your friend</title>
      <link>https://www.franzoni.eu/alan/disown-is-your-friend</link>
      <description>&lt;![CDATA[Bash builtin disown is a not-so-well known \job control command\] [http://www.gnu.org/software/bash/manual/html\node/Job-Control-Builtins.html), and yet&#xA;it&#39;s an extremely useful one.&#xA;&#xA;So what? You&#39;ve started a remote ssh session, launched some command which is taking very, very long to complete, and you just want to go home, or maybe you feel your connectivity may drop, and so on... and you forgot to launch screen (possibly with \[byobu\] https://launchpad.net/byobu))&#xA;or tmux before starting your work!&#xA;&#xA;Now you&#39;re desperate and you&#39;d just like to go home, but you fear your longstanding jobs will quit if you close your terminal.&#xA;&#xA;Just background your job, launch disown and all the jobs in background will receive no notification whatsoever of your saying goodbye to them; of course you won&#39;t be able to read their output to the terminal.&#xA;&#xA;#MostlyUnixish #linux #bash #ssh&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Bash builtin <em>disown</em> is a not-so-well known [job control command] <a href="http://www.gnu.org/software/bash/manual/html_node/Job-Control-Builtins.html" rel="nofollow">http://www.gnu.org/software/bash/manual/html_node/Job-Control-Builtins.html</a>), and yet
it&#39;s an extremely useful one.</p>

<p>So what? You&#39;ve started a remote ssh session, launched some command which is taking very, very long to complete, and you just want to go home, or maybe you feel your connectivity may drop, and so on... and you forgot to launch <a href="http://www.gnu.org/software/screen" rel="nofollow">screen</a> (possibly with [byobu] <a href="https://launchpad.net/byobu" rel="nofollow">https://launchpad.net/byobu</a>))
or <a href="http://tmux.sourceforge.net" rel="nofollow">tmux</a> before starting your work!</p>

<p>Now you&#39;re desperate and you&#39;d just like to go home, but you fear your longstanding jobs will quit if you close your terminal.</p>

<p>Just background your job, launch <em>disown</em> and all the jobs in background will receive no notification whatsoever of your saying goodbye to them; of course you won&#39;t be able to read their output to the terminal.</p>

<p><a href="/alan/tag:MostlyUnixish" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">MostlyUnixish</span></a> <a href="/alan/tag:linux" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">linux</span></a> <a href="/alan/tag:bash" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">bash</span></a> <a href="/alan/tag:ssh" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">ssh</span></a></p>
]]></content:encoded>
      <guid>https://www.franzoni.eu/alan/disown-is-your-friend</guid>
      <pubDate>Wed, 22 Aug 2012 20:35:00 +0000</pubDate>
    </item>
  </channel>
</rss>