snipt

Ctrl+h for KB shortcuts

Bash

Automatic SSH login

#If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:

$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.

# Copy your keys to the target server:

$ ssh-copy-id [email protected]
[email protected]'s password: 

# Now try logging into the machine, with ssh '[email protected]', and check in:

.ssh/authorized_keys

# to make sure we haven’t added extra keys that you weren’t expecting.
# Finally check logging in…

$ ssh [email protected]

[email protected]:~$ 

# You may also want to look into using ssh-agent if you want to try keeping your keys protected with a passphrase.
https://snipt.net/embed/d5dd568db0e0ad5597740e4a85403198/
/raw/d5dd568db0e0ad5597740e4a85403198/
d5dd568db0e0ad5597740e4a85403198
bash
Bash
27
2019-06-18T23:38:57
True
False
False
Oct 19, 2013 at 05:05 PM
/api/public/snipt/88737/
automatic-ssh-login
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a> <a href="#L-19">19</a> <a href="#L-20">20</a> <a href="#L-21">21</a> <a href="#L-22">22</a> <a href="#L-23">23</a> <a href="#L-24">24</a> <a href="#L-25">25</a> <a href="#L-26">26</a> <a href="#L-27">27</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>$ ssh-keygen -t rsa -b 2048 </span><span id="L-4"><a name="L-4"></a>Generating public/private rsa key pair. </span><span id="L-5"><a name="L-5"></a>Enter file in which to save the key <span class="o">(</span>/home/username/.ssh/id_rsa<span class="o">)</span>: </span><span id="L-6"><a name="L-6"></a>Enter passphrase <span class="o">(</span>empty <span class="k">for</span> no passphrase<span class="o">)</span>: </span><span id="L-7"><a name="L-7"></a>Enter same passphrase again: </span><span id="L-8"><a name="L-8"></a>Your identification has been saved in /home/username/.ssh/id_rsa. </span><span id="L-9"><a name="L-9"></a>Your public key has been saved in /home/username/.ssh/id_rsa.pub. </span><span id="L-10"><a name="L-10"></a> </span><span id="L-11"><a name="L-11"></a><span class="c1"># Copy your keys to the target server:</span> </span><span id="L-12"><a name="L-12"></a> </span><span id="L-13"><a name="L-13"></a>$ ssh-copy-id [email protected] </span><span id="L-14"><a name="L-14"></a>[email protected]<span class="s1">&#39;s password: </span> </span><span id="L-15"><a name="L-15"></a> </span><span id="L-16"><a name="L-16"></a><span class="s1"># Now try logging into the machine, with ssh &#39;</span>[email protected]<span class="err">&#39;</span>, and check in: </span><span id="L-17"><a name="L-17"></a> </span><span id="L-18"><a name="L-18"></a>.ssh/authorized_keys </span><span id="L-19"><a name="L-19"></a> </span><span id="L-20"><a name="L-20"></a><span class="c1"># to make sure we haven’t added extra keys that you weren’t expecting.</span> </span><span id="L-21"><a name="L-21"></a><span class="c1"># Finally check logging in…</span> </span><span id="L-22"><a name="L-22"></a> </span><span id="L-23"><a name="L-23"></a>$ ssh [email protected] </span><span id="L-24"><a name="L-24"></a> </span><span id="L-25"><a name="L-25"></a>[email protected]:~$ </span><span id="L-26"><a name="L-26"></a> </span><span id="L-27"><a name="L-27"></a><span class="c1"># You may also want to look into using ssh-agent if you want to try keeping your keys protected with a passphrase.</span> </span></pre></div> </td></tr></table>
bash, ssh