<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Ssh on Nicola Iarocci</title>
    <link>https://nicolaiarocci.com/tags/ssh/</link>
    <description>Recent content in Ssh on Nicola Iarocci</description>
    <generator>Hugo -- 0.143.1</generator>
    <language>en</language>
    <copyright>Produced / Written / Maintained by Nicola Iarocci since 2010</copyright>
    <lastBuildDate>Wed, 17 Mar 2021 07:05:25 +0100</lastBuildDate>
    <atom:link href="https://nicolaiarocci.com/tags/ssh/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Battling with SSH, cron jobs, and macOS Keyring</title>
      <link>https://nicolaiarocci.com/battling-with-ssh-cron-jobs-and-macos-keyring/</link>
      <pubDate>Wed, 17 Mar 2021 07:05:25 +0100</pubDate>
      <guid>https://nicolaiarocci.com/battling-with-ssh-cron-jobs-and-macos-keyring/</guid>
      <description>&lt;p&gt;So today, I was setting up a cronjob on my trusty MacBook Pro. The goal was to
backup some folders from a remote Linux server via rsync. The script is simple.
It goes something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rsync -avz -e &amp;quot;ssh -i ~/.ssh/my_rsa_keyfile&amp;quot; myuser@myserver:remotedir/ ~/localdir/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Launched by hand, it works seamlessly. Call it from a cron job via crontab, and
I get a permission denied error. I then enabled ssh &lt;code&gt;-v&lt;/code&gt; option to gather
a little intel on what was actually going on. As it turns out, the exact
error was:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>So today, I was setting up a cronjob on my trusty MacBook Pro. The goal was to
backup some folders from a remote Linux server via rsync. The script is simple.
It goes something like this:</p>
<pre><code>rsync -avz -e &quot;ssh -i ~/.ssh/my_rsa_keyfile&quot; myuser@myserver:remotedir/ ~/localdir/
</code></pre>
<p>Launched by hand, it works seamlessly. Call it from a cron job via crontab, and
I get a permission denied error. I then enabled ssh <code>-v</code> option to gather
a little intel on what was actually going on. As it turns out, the exact
error was:</p>
<pre><code>`read_passphrase: can't open /dev/tty: Device not configured`
</code></pre>
<p>Quite puzzling. Long story short, the error message was misleading. It took me
an embarrassingly long time to figure out what the real problem was. The
identity file I was using has a passphrase, which is saved in macOS Keyring.
When the <code>ssh -i</code> command is launched via cron, no Keyring is used. Not unless
you explicitly instruct ssh to do. See, my <code>~/.ssh/config</code> file was something
like this:</p>
<pre><code>Host *
    ServerAliveInterval 360
    AddKeysToAgent yes

[...]

Host myserver
    HostName 123.123.123.123
    User myuser
</code></pre>
<p>See, in <code>myserver</code> section there was no <code>Usekeychain</code> option. Launching the
script interactively worked because of <code>AddkeysToAgent</code> in the general section.
It enables the ssh-agent for the current terminal session, for all hosts. But
cron jobs, well, they don&rsquo;t run in the same session, and certainly don&rsquo;t run
the agent. I could eval the agent in the script, of course, but the
simplest solution was to update <code>myserver</code> section:</p>
<pre><code>Host myserver
    HostName 123.123.123.123
    Usekeychain yes
    User myuser
</code></pre>
<p>Now ssh knows it should use the keychain when resolving <code>myserver</code> RSA key,
even when no agent is running. I am not sure why I did not have <code>Usekeychain</code>
there; I do have it enabled for other hosts in the same file. As said, I wasted
way too much time on this issue. At least, I hope my experience will be useful
to someone else, or, more likely, to my future self in a few months or years.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Primi passi con SSH</title>
      <link>https://nicolaiarocci.com/primi-passi-con-ssh/</link>
      <pubDate>Wed, 23 May 2012 00:00:00 +0000</pubDate>
      <guid>https://nicolaiarocci.com/primi-passi-con-ssh/</guid>
      <description>&lt;p&gt;Se siete ai primi passi nello sviluppo di applicazioni web vi consiglio la lettura di &lt;!-- raw HTML omitted --&gt;SSH: What and How&lt;!-- raw HTML omitted --&gt;. Senza troppi fronzoli l’articolo spiega le basi di SSH mettendo bene in luce le possibilità offerte da questo importante strumento di lavoro.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ogni giorno molti sviluppatori web usano SSH (“Secure Shell”) per gestire i loro server, fare backup, lavorare in remoto e una miriade di altre cosette. Oggi vi spiego cos’è e da dove viene SSH e, soprattutto, vi insegno come configurarlo sul vostro server remoto o sulla vostra rete locale. Cominciamo!&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Se siete ai primi passi nello sviluppo di applicazioni web vi consiglio la lettura di <!-- raw HTML omitted -->SSH: What and How<!-- raw HTML omitted -->. Senza troppi fronzoli l’articolo spiega le basi di SSH mettendo bene in luce le possibilità offerte da questo importante strumento di lavoro.</p>
<blockquote>
<p>Ogni giorno molti sviluppatori web usano SSH (“Secure Shell”) per gestire i loro server, fare backup, lavorare in remoto e una miriade di altre cosette. Oggi vi spiego cos’è e da dove viene SSH e, soprattutto, vi insegno come configurarlo sul vostro server remoto o sulla vostra rete locale. Cominciamo!</p></blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
