<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Tag: Encryption - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/encryption/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Tue, 28 Jan 2020 03:26:04 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Tag: Encryption - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Upgrade SSH keys and use gpg-agent with Ed25519 keys</title>
		<link>https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 11 Feb 2018 16:30:46 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1245</guid>

					<description><![CDATA[<p>SSH keys are convenient and more secure than using a password to authenticate. If you created your SSH key a while ago, it's probably time to generate new RSA 4096 and Ed25519 keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SSH keys are very convenient and more secure than using only a password to authenticate. If you created your SSH key a while ago, it&#8217;s probably time to generate new keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048. But really, it&#8217;s time to start using RSA 4096 for legacy servers, and Ed25519 for servers with modern ssh key support.</p>
<p><span id="more-1245"></span></p>
<p>The below commands are based on the post <a href="https://blog.g3rt.nl/upgrade-your-ssh-keys.html" target="_blank" rel="noopener noreferrer">Upgrade your SSH keys.</a> Check that out for more details.</p>
<h2>Identify and rename old ssh keys</h2>
<p>First, identify your old ssh keys:</p>
<pre>$ cd ~/.ssh
$ for sshkey in $(ls *.pub);do echo $sshkey;ssh-keygen -lf $sshkey;done
/home/ryan/.ssh/id_rsa.pub
2048 SHA256:gIDkzI98pEna3j9+2Ja5di0+k2dCaXtCtx6k71dskA1 ryan@home (RSA)</pre>
<p>From the output, this is showing it is an RSA 2048 key.</p>
<p>Next rename your old public and private ssh keys:</p>
<pre>$ mv id_rsa.pub id_rsa_legacy.pub
$ mv id_rsa id_rsa_legacy</pre>
<h2>Stop using insecure keys</h2>
<p>Use only keys that are greater than RSA 2048, or Ed25519.<br />
Specifically, remove:</p>
<ul>
<li>DSA</li>
<li>RSA 1024 and 2048</li>
<li>ECDSA</li>
</ul>
<p>Just be sure you aren&#8217;t using these ssh keys. Only remove them when you no longer need them and have the new keys setup and working.</p>
<h2>Create or Change your existing password</h2>
<p>If you old RSA ssh key didn&#8217;t use a password, now is the time to set a password. You can upgrade ssh keys that previously existed and didn&#8217;t use a password, without breaking anything. Also adding 100 rounds helps make your old key more secure when at rest if you need to continue using it.</p>
<pre>$ ssh-keygen -f ~/.ssh/id_rsa_legacy -p -o -a 100</pre>
<h2>Upgrade ssh keys &#8211; Generate RSA 4096 ssh keys</h2>
<p>RSA 4096 is good to use for legacy systems which do not yet support the new Ed25519 key.</p>
<p>Generate the RSA 4096 keys, and make sure to use a strong password:</p>
<pre>$ ssh-keygen -t rsa -b 4096 -o -a 100
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ryan/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_rsa.
Your public key has been saved in /home/ryan/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:732MQCPPaMS815Y7MFXl4n2WXuawR1Zsat+PEG1TnPA ryan@home
The key's randomart image is:
+---[RSA 4096]----+
|         +. o+.oo|
|        o * .+*..|
|         B oo=Eo.|
|          =o=..oo|
|        S .BoBo+=|
|         .  *.Ooo|
|          .  B =.|
|        .   B * .|
|          .... . |
+----[SHA256]-----+</pre>
<p>The &#8220;<code>-o -a 100</code>&#8221; means it is harder to crack the private key&#8217;s password using brute-force attacks. If your legacy system doesn&#8217;t support this, remove this option.</p>
<h2>Upgrade ssh keys &#8211; Generate Ed25519 ssh keys</h2>
<p><a href="https://en.wikipedia.org/wiki/EdDSA#Ed25519" target="_blank" rel="noopener noreferrer">Ed25519</a> ssh keys work on modern systems (OpenSSH 6.7+) and are much shorter than RSA keys. Note, the &#8220;<code>-o -a 100</code>&#8221; option is implied with Ed25519 key generation.<br />
Generate your new Ed25519 key and use a strong password:</p>
<pre>$ ssh-keygen -t ed25519
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_ed25519.
Your public key has been saved in /home/ryan/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM ryan@home
The key's randomart image is:
+--[ED25519 256]--+
|        . .      |
|     . . . . .   |
|    . o .   o o .|
|   .   + . o o = |
|    . + S * + +  |
|     = . = B  .E |
|      + B.=.oo ..|
|       =.=o.o ..=|
|      ..oo=+o..+=|
+----[SHA256]-----+</pre>
<p>Now you have both RSA 4096 and Ed25519 ssh keys ready to go.</p>
<p>Next, add the keys to your ssh agent so it will remember the keys for you.</p>
<h2>Install and configure ssh agent</h2>
<p>Using an ssh agent allows you to type in a password once, and then the agent remembers the ssh keys.</p>
<p>On Ubuntu 16.04 there is one problem though. The built-in Gnome-keyring doesn&#8217;t support Ed25519. To work-around this, you could use the normal ssh-agent. But, I suggest instead to use gpg-agent and disable the gnome-keyring.</p>
<p>The below commands are based on the <a href="https://wiki.archlinux.org/index.php/GnuPG#SSH_agent" target="_blank" rel="noopener noreferrer">Arch wiki</a> and an answer from the <a href="https://askubuntu.com/questions/732581/gpg-agent-and-ssh-no-keys/930105#930105" target="_blank" rel="noopener noreferrer">Ask Ubuntu Forum</a>.</p>
<p>Disable Gnome ssh keyring daemon (<a href="https://wiki.archlinux.org/index.php/GNOME/Keyring#Disable_keyring_daemon_components" target="_blank" rel="noopener noreferrer">reference</a>):</p>
<pre>$ cp -rp /etc/xdg/autostart/gnome-keyring-ssh.desktop ~/.config/autostart
$ echo "Hidden=true" &gt;&gt; ~/.config/autostart/gnome-keyring-ssh.desktop</pre>
<p>Install gpg-agent:</p>
<pre>$ sudo apt-get install gpa gnupg-curl</pre>
<p>Enable ssh support in gpg-agent, and set a timeout to remember the key and password for 1 hour, since this adds some convenience:</p>
<pre>$ echo "enable-ssh-support" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "default-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "max-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf</pre>
<p>Edit your .bashrc to automatically load gpg-agent when you log in.</p>
<pre>$ vi ~/.bashrc
# Set SSH to use gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="~/.gnupg/S.gpg-agent.ssh"
fi</pre>
<p>Reload gpg-agent:</p>
<pre>$ gpg-connect-agent reloadagent /bye</pre>
<p>Next, add your new ssh keys to the gpg-agent:</p>
<pre>$ ssh-add ~/.ssh/id_ed25519 ~/.ssh/id_rsa ~/.ssh/id_rsa_legacy</pre>
<p>You will be prompted to enter your ssh key password. And after you enter that, another prompt will pop-up, from the gpg-agent. It will be used to unlock the gpg-agent&#8217;s key storage. This should be a different password than the password for your ssh keys. You will be prompted to enter this password every time you log in, or after the 1 hour timeout.</p>
<p>Enter the password that you want to use to unlock the gpg-agent key storage. And if you use the same password here for all your ssh keys, you only have to unlock it once:</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1270" src="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png" alt="gpg-agent password prompt upgrade ssh keys" width="477" height="277" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png 477w, https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt-300x174.png 300w" sizes="(max-width: 477px) 100vw, 477px" /></p>
<p>And now you can list your keys stored in the gpg-agent:</p>
<pre>$ ssh-add -l -E md5 # list fingerprint using md5 hash
$ ssh-add -l        # list fingerprint using sha256 hash
$ ssh-add -L        # list public key parameters</pre>
<h2>Re-deploy the new public keys</h2>
<p>Lastly, you need to add your new public keys to your servers. This command will ssh to your server and add your new public keys to the authorized_keys file.<br />
Change <code>1.2.3.4</code> to your server&#8217;s IP:</p>
<pre>$ ssh 1.2.3.4 "mkdir -p .ssh;echo $(cat ~/.ssh/id_ed25519.pub) &gt;&gt; .ssh/authorized_keys;echo $(cat ~/.ssh/id_rsa.pub) &gt;&gt; .ssh/authorized_keys;chmod 700 .ssh;chmod 640 .ssh/authorized_keys"</pre>
<p>Be sure to do this for ever server you connect to.</p>
<p><strong>Important</strong>: Be sure you <strong>don&#8217;t lock yourself out</strong> of your servers. Have another session open and test to make sure you can log in again after making this change.</p>
<p>Now you can remove your old ssh key from the ssh agent and only use the secure ssh keys:</p>
<pre>$ ssh-add -d 2&gt;/dev/null;ssh-add ~/.ssh/id_ed25519;ssh-add ~/.ssh/id_rsa</pre>
<p>Be sure to add the Ed25519 key first, like above. Since it seems to be a feature that prioritizes RSA keys first. So add the Ed25519 key first.</p>
<p>SSH to your servers to test the new key is working. You can also see in the logs the type of ssh key being used.</p>
<p>Confirm using the new Ed25519 ssh key, on Ubuntu 16.04:</p>
<pre>$ grep " sshd\[" /var/log/auth.log|grep "Accepted publickey"|tail
Feb 11 10:00:00 home sshd[1802]: Accepted publickey for ryan from 192.168.1.100 port 60708 ssh2: ED25519 SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM</pre>
<h2>Conclusion</h2>
<p>Now you have more secure ssh keys since you are using Ed25519 and RSA 4096 keys. You have been able to upgrade ssh keys that are insecure! Next, you should look into updating your ssh server and client settings to use better encryption settings, using <a href="https://stribika.github.io/2015/01/04/secure-secure-shell.html" target="_blank" rel="noopener noreferrer">these</a> <a href="https://wiki.mozilla.org/Security/Guidelines/OpenSSH" target="_blank" rel="noopener noreferrer">references</a>.</p>
<p>And if you don&#8217;t want to manually deploy the new ssh keys to all of your servers, instead you can use <a href="https://ryandaniels.ca/blog/ansible-user-management/">Ansible for user management</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1245</post-id>	</item>
	</channel>
</rss>
