<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Smallstep</title>
    <description>The latest articles on Forem by Smallstep (@smallstep).</description>
    <link>https://forem.com/smallstep</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F2807%2Fd11a3208-785f-4937-8c9d-00cc17cdc5ee.png</url>
      <title>Forem: Smallstep</title>
      <link>https://forem.com/smallstep</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/smallstep"/>
    <language>en</language>
    <item>
      <title>DIY SSH Bastion Host</title>
      <dc:creator>Carl Tashian</dc:creator>
      <pubDate>Tue, 01 Sep 2020 19:15:00 +0000</pubDate>
      <link>https://forem.com/smallstep/diy-ssh-bastion-hosts-34b2</link>
      <guid>https://forem.com/smallstep/diy-ssh-bastion-hosts-34b2</guid>
      <description>&lt;p&gt;Let's build and configure a minimal SSH bastion host (jump box) from scratch, using Ubuntu 20.04 LTS.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's a bastion host?
&lt;/h2&gt;

&lt;p&gt;Bastion is a military term meaning "a projecting part of a fortification."&lt;/p&gt;

&lt;p&gt;In the same way that a home WiFi router sits between the vast and perilous internet and the often insecure devices on a local network, a bastion host sits between the public internet and an internal network (a VPC, for example), acting as a gateway to reach the internal hosts while protecting them from direct exposure to the wilds of the public internet. Bastion hosts often run OpenSSH or a remote desktop server.&lt;/p&gt;

&lt;p&gt;A bastion host serves as an important choke point in a network. Given its position, it &lt;em&gt;can&lt;/em&gt; take on a lot of responsibilities: auditing and session logging, user authentication for internal hosts, and advanced threat detection. But it doesn't need to do all that. We're going to keep things simple here and build a bastion from scratch that supports the proxying of SSH connections. Then we'll talk about some fancier stuff we could do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a bastion host?
&lt;/h2&gt;

&lt;p&gt;If you have an internal network and you need to reach those hosts from the public internet, a bastion host is an easy option.&lt;/p&gt;

&lt;p&gt;Do you even need a bastion? As with nearly any decision in technology, it depends. Here are some alternatives you might consider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternatives to bastions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Set up an IPsec VPN
&lt;/h3&gt;

&lt;p&gt;If you need deeper access to your internal network than you can get with SSH or RDP, you may want a VPN.&lt;br&gt;
But IPsec VPNs add a lot of complexity and maintenance burden compared to the other options, including bastion hosts.&lt;/p&gt;
&lt;h3&gt;
  
  
  Set up an overlay network
&lt;/h3&gt;

&lt;p&gt;An overlay network is a lighter and simpler kind of VPN that supports roaming endpoints. It still takes a bit of setup. The most common open source options for this are &lt;a href="https://www.wireguard.com/"&gt;Wireguard&lt;/a&gt; and &lt;a href="https://slack.engineering/introducing-nebula-the-open-source-global-overlay-network-from-slack-884110a5579"&gt;Nebula&lt;/a&gt;. You could run one of these at the edge of your internal network (like a VPN), or on all the hosts you want to be able to access, and tunnel SSH traffic through it. All of your clients will also need to run Wireguard or Nebula.&lt;/p&gt;
&lt;h3&gt;
  
  
  Use a hosted proxy
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/iap/"&gt;Google IAP&lt;/a&gt; and &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html"&gt;AWS Session Manager&lt;/a&gt; are hosted solutions that tunnel SSH traffic to your internal cloud network. The benefit here is that you can use cloud IAM roles for authentication and you can implement more sophisticated security policies (security key policies, or device-level policies rather than IP-based policies) that aren't feasible if you run your own bastion host. These services are free to use, but the drawback is that IAP and AWS Session Manager are more complex than pure SSH, and they add some lock-in to GCP or AWS.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up a bastion
&lt;/h2&gt;

&lt;p&gt;Let's make some assumptions: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We only want this bastion to forward SSH connections to our internal hosts. Because we're using SSH here, users will have to authenticate both to the bastion, then to the internal host. To complete the connection, users will need valid credentials for both hosts, but &lt;em&gt;it's possible to use different credentials for the bastion and the internal host&lt;/em&gt;, and we're going to take advantage of that feature.&lt;/li&gt;
&lt;li&gt;We'll have a single shared user for everyone, and no interactive terminal sessions allowed.&lt;/li&gt;
&lt;li&gt;Users will connect to internal hosts using &lt;code&gt;ssh -J [bastion] [internal host]&lt;/code&gt;, or with the &lt;code&gt;ProxyJump&lt;/code&gt; directive in a &lt;code&gt;Match Host&lt;/code&gt; block of their &lt;code&gt;.ssh/config&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Launch an instance.
&lt;/h3&gt;

&lt;p&gt;Stand up a Linux instance on your favorite cloud provider. We'll use Ubuntu 20.04 LTS because it is simple, it's well supported, and it includes the recently-released OpenSSH 8.2.&lt;/p&gt;

&lt;p&gt;Set up a firewall or security group policy to restrict connections to the bastion to port 22 (SSH), and, if you can, only allow connections from IPs you trust.&lt;/p&gt;
&lt;h3&gt;
  
  
  Configure the bastion
&lt;/h3&gt;

&lt;p&gt;We'll need to do a few things to get our bastion ready.&lt;/p&gt;
&lt;h5&gt;
  
  
  Configure OpenSSH
&lt;/h5&gt;

&lt;p&gt;We recommend enforcing &lt;a href="https://infosec.mozilla.org/guidelines/openssh"&gt;Mozilla's OpenSSH security guide&lt;/a&gt;. Unfortunately their guide only covers up to OpenSSH 6.7. Here are the guidelines that are still relevant to OpenSSH 8.2:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deactivate short moduli&lt;/strong&gt;. Moduli are used for key exchange at the start of an SSH connection. Mozilla recommends only using 3071-bit or greater moduli for extra security. To enforce this, run:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'$5 &amp;gt;= 3071'&lt;/span&gt; /etc/ssh/moduli &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/ssh/moduli.tmp &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv&lt;/span&gt; /etc/ssh/moduli.tmp /etc/ssh/moduli&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt;, consider the following SSHD config parameters:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Supported HostKey algorithms by order of preference.
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_rsa_key

# Password based logins are disabled - only public key based logins are allowed.
AuthenticationMethods publickey

# LogLevel VERBOSE logs user's key fingerprint on login. 
# Needed to have a clear audit track of which key was using to log in.
LogLevel VERBOSE

PermitRootLogin no

# Log sftp level file access (read/write/etc.) that would not be easily logged otherwise.
Subsystem sftp  /usr/lib/ssh/sftp-server -f AUTHPRIV -l INFO
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;You should also consider which algorithms and key types you'd like to support. Mozilla recommends the following key types (more restrictive than the OpenSSH defaults):
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;On top of Mozilla's recommendations (which only cover up to OpenSSH 6.7), here are some things you can do to beef up your SSHD security:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Require a security key&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;You can set up SSHD to only accept keys that use FIDO U2F security tokens.&lt;br&gt;
&lt;/p&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PubkeyAcceptedKeyTypes sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This will prevent future connections to the host using the original PEM key you got upon launch. So, you'll need to generate a new &lt;code&gt;-sk&lt;/code&gt; type key for the &lt;code&gt;ubuntu&lt;/code&gt; account. &lt;a href="https://smallstep.com/blog/ssh-tricks-and-tips/#add-a-second-factor-to-your-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;We wrote instructions for that here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This requires all of your clients to have OpenSSH 8.2+.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you do not want to restrict access by IP address in your security group rules, consider some additional hardening:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change your default SSH port. This will deter a lot of basic bots.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Port 37271
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://help.ubuntu.com/community/PortKnocking"&gt;Set up port knocking&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Port knocking will complicate the task of connecting to the bastion, but it could be a good option if you need your bastion to be available to any IP address.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install &lt;a href="https://en.wikipedia.org/wiki/Host-based_intrusion_detection_system_comparison"&gt;intrusion detection&lt;/a&gt; and prevention software&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Disable Forwarding
&lt;/h5&gt;

&lt;p&gt;Since we're not allowing shell access, we also want to prohibit all forwarding except TCP forwarding, which &lt;code&gt;ssh -J&lt;/code&gt; uses to support bastions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AllowAgentForwarding no
AllowStreamLocalForwarding no
X11Forwarding no
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If all you need is an SSH gateway, you can disable shell access on the bastion itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Match User *,!ubuntu
        ForceCommand /bin/echo 'This bastion does not support interactive commands.'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By default, SSHD's TCP port forwarding will allow the user to forward their connection to any remote TCP port in your private network. You can limit forwarding to port 22 (SSH) if you don't want other kinds of traffic to be forwarded to internal hosts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PermitOpen *:22
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Restart SSHD (and cross your fingers)
&lt;/h3&gt;

&lt;p&gt;You can test your configuration with &lt;code&gt;sshd -t&lt;/code&gt;, then restart the SSHD server. Make sure you can still &lt;code&gt;ssh&lt;/code&gt; into the machine before you continue! 😱&lt;/p&gt;

&lt;h3&gt;
  
  
  Send your users SSH keys to the bastion
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you only have a few users, you can create a single account on the bastion that everyone will use, and make sure all of their public keys are added to it.&lt;/li&gt;
&lt;li&gt;If you have lots of users, use &lt;a href="https://smallstep.com/sso-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;Smallstep SSH&lt;/a&gt; and issue short-lived SSH certificates.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Send logs to the cloud
&lt;/h3&gt;

&lt;p&gt;You can &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html"&gt;set up the AWS CloudWatch agent&lt;/a&gt; or the Google &lt;a href="https://cloud.google.com/logging/docs/agent"&gt;Cloud Logging Agent&lt;/a&gt;, so that your SSH logs in particular will go to the cloud. With this in place, you can set up alerts for suspicious SSH activity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Allow emergency root access
&lt;/h3&gt;

&lt;p&gt;See our &lt;a href="https://smallstep.com/blog/ssh-emergency-access?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;SSH Emergency Access&lt;/a&gt; guide for a safe approach that allows emergency access to the host.&lt;/p&gt;

&lt;p&gt;Once you have set up emergency access keys, you can disable any other option for root access—since no one will regularly have a reason to use the &lt;code&gt;root&lt;/code&gt; account on this machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up your internal hosts to only allow SSH access from the bastion
&lt;/h3&gt;

&lt;p&gt;This is an important Zero Trust policy: Any internal host you connect to should only allow SSH connections from the bastion. The easiest way to implement this is with an inbound 1G&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure your SSH clients.
&lt;/h3&gt;

&lt;p&gt;Your clients should accept new host keys offered by a known host, making host key rotation a lot easier. (This will be the default in a future OpenSSH.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UpdateHostKeys yes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And, you can add a configuration directive to make it easier to reach your internal hosts via the bastion. Let's say all of your internal hosts have names in the .internal domain, as is the case on AWS. You can use this directive to reach them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host *.internal
  ProxyJump bastion.example.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, just &lt;code&gt;ssh host.internal&lt;/code&gt; to connect to an internal host via the bastion. One subtle note here: The internal hostname will be resolved via DNS lookup on the bastion, not by your local machine. So as long as the bastion knows how to look up your internal hosts by their internal names and IPs, that's all you need.&lt;/p&gt;




&lt;p&gt;To learn more about SSH certificates visit &lt;a href="https://smallstep.com/sso-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;the Smallstep website&lt;/a&gt;. You can even try our free hosted offering and experience the value of SSH certificates in under five minutes!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>If you’re not using SSH certificates you’re doing SSH wrong | Episode 3: An ideal SSH flow</title>
      <dc:creator>Cass Fultz</dc:creator>
      <pubDate>Fri, 21 Aug 2020 19:18:44 +0000</pubDate>
      <link>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-3-an-ideal-ssh-flow-5fc</link>
      <guid>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-3-an-ideal-ssh-flow-5fc</guid>
      <description>&lt;p&gt;In our previous two episodes, we covered the &lt;a href="https://dev.to/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-1-keys-versus-certificates-5a0n"&gt;benefits of SSH certificates&lt;/a&gt; and how they can &lt;a href="https://dev.to/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-2-certificates-improve-usability-operability-security-45hg"&gt;help developers, operators, and security teams&lt;/a&gt; better manage privileged access. Today we will look at an ideal SSH flow using certificates and your existing identity provider for single sign-on access. &lt;/p&gt;

&lt;h3&gt;
  
  
  An ideal SSH flow
&lt;/h3&gt;

&lt;p&gt;SSH certificate authentication is the foundation of what I think is the ideal SSH flow.&lt;/p&gt;

&lt;p&gt;To SSH, users first run a login command in their terminal (e.g., &lt;code&gt;step ssh login&lt;/code&gt;):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ step ssh login
Your default web browser has been opened for you to login: https://accounts.google.com/...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A browser is opened and an SSO flow is initiated at your organization's identity provider:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltzmp5x1crt1eqv4st0s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltzmp5x1crt1eqv4st0s.png" alt="User authenticates in browser via SSO" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A web-based SSO flow makes it easy to leverage strong MFA (e.g., FIDO U2F) and any other advanced authentication capabilities your identity provider offers. Users login with a familiar flow, and removing a user from your canonical identity provider ensures prompt termination of SSH access.&lt;/p&gt;

&lt;p&gt;Once the user completes SSO, a bearer token (e.g., an OIDC identity token) is returned to the login utility. The utility generates a new key pair and requests a signed certificate from the CA, using the bearer token to authenticate and authorize the certificate request.&lt;/p&gt;

&lt;p&gt;The CA returns a certificate with an expiry long enough for a work day (e.g., 16-20 hours). The login utility automatically adds the signed certificate and corresponding private key to the user's &lt;code&gt;ssh-agent&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Users needn't be aware of any of this detail. All they need to know is that, in order to use SSH, they must first run &lt;code&gt;step ssh login&lt;/code&gt;. Once that's done they can use SSH like normal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh prod01.example.com
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1036-gcp x86_64)

Last login: Wed Sep 11 04:04:51 2019 from 98.210.132.79
mmalone@prod01:~$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Like browser cookies, short-lived certificates issued by this flow are ephemeral credentials, lasting just long enough for one work day. Like logging into a website, logging into SSH creates a session. It's a simple process that must be completed, at most, once per day. This is infrequent enough that strong MFA can be used without frustrating or desensitizing users.&lt;/p&gt;

&lt;p&gt;New private keys and certificates are generated automatically every time the user logs in, and they never touch disk. Inserting directly into &lt;code&gt;ssh-agent&lt;/code&gt; insulates users from sensitive credentials. If a user wants to connect from a different device it's easier for them to run &lt;code&gt;step ssh login&lt;/code&gt; there than it is to exfiltrate keys from &lt;code&gt;ssh-agent&lt;/code&gt; and reuse them.&lt;/p&gt;

&lt;p&gt;There are lots of possible variations of this flow. You can adjust the certificate expiry, use PAM authentication at the CA instead of SSO, generate the private key on a smart card or TPM, opt not to use &lt;code&gt;ssh-agent&lt;/code&gt;, or move MFA to the actual SSH connection. Personally, I think this combination offers the best balance of security and usability. Indeed, relative to most existing SSH deployments it's operationally simpler, more secure, and more usable.&lt;/p&gt;

&lt;p&gt;Critics of SSH certificate authentication say that it's new, not well supported, and the tooling doesn't exist to use certificates in practice. The truth is, &lt;strong&gt;certificate authentication was added in&lt;/strong&gt; &lt;a href="https://www.openssh.com/txt/release-5.4" rel="noopener noreferrer"&gt;&lt;strong&gt;OpenSSH 5.4&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;almost a decade ago&lt;/strong&gt;. It's battle tested and used in production by massive operations. And the tooling required to build this ideal SSH flow is available today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;There are lots of existing tools for managing SSH certificates. Here are a few:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/smallstep/certificates" rel="noopener noreferrer"&gt;&lt;code&gt;step-ca&lt;/code&gt;&lt;/a&gt; is now an SSH CA (in addition to being an X.509 CA)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/smallstep/cli" rel="noopener noreferrer"&gt;&lt;code&gt;step&lt;/code&gt;&lt;/a&gt; makes it easy for users and hosts to get certificates from &lt;code&gt;step-ca&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ssh-keygen&lt;/code&gt; can generate root certificates and sign user &amp;amp; host certificates&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/netflix/bless" rel="noopener noreferrer"&gt;&lt;code&gt;netflix/bless&lt;/code&gt;&lt;/a&gt; is Netflix's SSH CA that runs in AWS Lambda and uses IAM&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/nsheridan/cashier" rel="noopener noreferrer"&gt;&lt;code&gt;nsheridan/cashier&lt;/code&gt;&lt;/a&gt; is Intercom's SSH CA&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/uber/pam-ussh" rel="noopener noreferrer"&gt;&lt;code&gt;uber/pam-ussh&lt;/code&gt;&lt;/a&gt; lets you use certificates to authorize &lt;code&gt;sudo&lt;/code&gt; use&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hashicorp/vault" rel="noopener noreferrer"&gt;&lt;code&gt;hashicorp/vault&lt;/code&gt;&lt;/a&gt; has an &lt;a href="https://www.vaultproject.io/docs/secrets/ssh/index.html" rel="noopener noreferrer"&gt;SSH secrets engine&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the appropriate configuration of &lt;code&gt;step-ca&lt;/code&gt; you can use &lt;code&gt;step&lt;/code&gt; to:&lt;/p&gt;

&lt;h3&gt;
  
  
  Get a host certificate automatically at startup
&lt;/h3&gt;

&lt;p&gt;To demonstrate, let's create a new EC2 instance with the &lt;code&gt;aws&lt;/code&gt; CLI tool. The interesting bits are tucked in &lt;a href="https://github.com/smallstep/step-ssh-example/blob/master/host-bootstrap.sh" rel="noopener noreferrer"&gt;some light configuration&lt;/a&gt; (using a &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" rel="noopener noreferrer"&gt;user-data startup script&lt;/a&gt;) that gets a host certificate and enables certificate authentication for users:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws ec2 run-instances --image-id ami-07d0cf3af28718ef8 \
    --count 1 --instance-type t2.micro \
    --key-name mike-test \
    --security-group-ids launch-wizard-7 \
    --user-data file://startup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: you should be able to use our &lt;a href="https://smallstep.com/blog/embarrassingly-easy-certificates-on-aws-azure-gcp/" rel="noopener noreferrer"&gt;instance identity document support&lt;/a&gt; here, but we've got a few kinks to work out. Stay tuned.&lt;/p&gt;

&lt;h3&gt;
  
  
  Get a user certificate using SSO (OAuth OIDC)
&lt;/h3&gt;

&lt;p&gt;Now we'll use &lt;code&gt;step ssh certificate&lt;/code&gt; locally (you can &lt;code&gt;brew install step&lt;/code&gt;) to generate a new key pair, get a certificate from the CA &lt;a href="https://smallstep.com/blog/easily-curl-services-secured-by-https-tls/#personal-certificates-via-oauth-openid-connect" rel="noopener noreferrer"&gt;using SSO&lt;/a&gt;, and automatically add the certificate and private key to &lt;code&gt;ssh-agent&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That sounds like a lot, but it's just one command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ step ssh certificate mike@smallstep.com id_ecdsa
✔ Provisioner: Google (OIDC)
Your default web browser has been opened to visit:

https://accounts.google.com/o/oauth2/v2/auth?client_id=650...

✔ CA: https://ca.internal
✔ Private Key: id_ecdsa
✔ Public Key: id_ecdsa.pub
✔ Certificate: id_ecdsa-cert.pub
✔ SSH Agent: yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once that's done we can SSH to the instance we just created, using certificate authentication, with no TOFU!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh mike@ec2-100-26-100-55.compute-1.amazonaws.com
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1044-aws x86_64)

Last login: Thu Sep 12 02:25:43 2019 from 98.210.132.79
mike@ip-172-31-70-94:~$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For more info check out our &lt;a href="https://smallstep.com/docs/getting-started/" rel="noopener noreferrer"&gt;getting started guide&lt;/a&gt; and &lt;a href="https://github.com/smallstep/step-ssh-example" rel="noopener noreferrer"&gt;SSH example repo&lt;/a&gt;. Make sure you pass the &lt;code&gt;--ssh&lt;/code&gt; flag to &lt;code&gt;step ca init&lt;/code&gt; when you're setting up the CA (the getting started guide doesn't do this).&lt;/p&gt;

&lt;p&gt;There's a lot more that can be done to make SSH certificate authentication even more awesome. We're working on that. If you have any ideas, &lt;a href="https://gitter.im/smallstep/community" rel="noopener noreferrer"&gt;let us know&lt;/a&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  Use SSH certificates
&lt;/h3&gt;

&lt;p&gt;SSH certificate authentication does a lot to improve SSH. It eliminates spurious TOFU warnings and host key verification failures. It lets you drop complex key approval &amp;amp; distribution processes and extend SSO to SSH. It makes rekeying possible for hosts and easier than key reuse for users. It makes SSH keys ephemeral, making key management oversights fail-secure.&lt;/p&gt;

&lt;p&gt;You can deploy an SSH CA and reconfigure hosts in a matter of minutes. It's easy to transition — you can continue supporting public key authentication at the same time.&lt;/p&gt;

&lt;p&gt;SSH certificate authentication is the right way to do SSH.&lt;/p&gt;

&lt;p&gt;To learn more about SSH certificates visit &lt;a href="https://smallstep.com/sso-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;the Smallstep website&lt;/a&gt;. You can even try our free hosted offering and experience the value of SSH certificates in under five minutes!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>security</category>
      <category>opensource</category>
      <category>sre</category>
    </item>
    <item>
      <title>If you’re not using SSH certificates you’re doing SSH wrong | Episode 2: Certificates improve usability, operability, &amp; security</title>
      <dc:creator>Cass Fultz</dc:creator>
      <pubDate>Fri, 21 Aug 2020 19:04:52 +0000</pubDate>
      <link>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-2-certificates-improve-usability-operability-security-45hg</link>
      <guid>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-2-certificates-improve-usability-operability-security-45hg</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-1-keys-versus-certificates-5a0n"&gt;In our previous post&lt;/a&gt;, we discussed the benefits of using certificates over keys for SSH. In this episode we wanted to highlight how switching to certificates improves the lives of developers, operators, and security teams.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Certificate authentication improves usability
&lt;/h3&gt;

&lt;p&gt;With public key authentication, when you SSH to a remote host for the first time, you'll be presented with a security warning like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh ubuntu@ec2-54-161-77-102.compute-1.amazonaws.com
The authenticity of host 'ec2-54-161-77-102.compute-1.amazonaws.com (54.161.77.102)' can't be established.
ECDSA key fingerprint is SHA256:2ae53QcOB0W6HO+XtPmMXk7To/MvMuhFxTj8ZD7eSsE.
Are you sure you want to continue connecting (yes/no)?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You've probably seen this before. If you're like most people, you've been trained to ignore it by just typing "yes". That's a problem because this is a legitimate security threat. It's also a pretty horrendous user experience. I'd wager the vast majority of SSH users don't actually understand this warning.&lt;/p&gt;

&lt;p&gt;When you SSH to a host, the host authenticates you. Your SSH client also attempts to authenticate the host. To do so your client needs to know the host's public key. Host public keys are stored in a simple database in &lt;code&gt;~/.ssh/known_hosts&lt;/code&gt;. If your client can't find the host's public key in this database you get this warning. &lt;strong&gt;It's telling you that the host can't be authenticated!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgxtd0kft7507g8p4oh1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgxtd0kft7507g8p4oh1.png" alt="Browser certificate warning is equivalent to TOFU" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What you're &lt;em&gt;supposed&lt;/em&gt; to do is verify the key fingerprint out-of-band by asking an administrator or consulting a database or something. But no one does that. When you type "yes" the connection proceeds without authentication and the public key is permanently added to &lt;code&gt;~/.ssh/known_hosts&lt;/code&gt;. This is the &lt;em&gt;trust on first use&lt;/em&gt; (TOFU) anti-pattern.&lt;/p&gt;

&lt;p&gt;Since certificate authentication uses certificates to communicate public key bindings, clients are always able to authenticate, even if it's the first time connecting to a host. &lt;strong&gt;TOFU warnings go away.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Certificate authentication also offers a convenient place to gate SSH with custom authentication: when the certificate is issued. This can be leveraged to further enhance SSH usability. In particular, it let's you extend single sign-on (SSO) to SSH. SSO for SSH is certificate authentication's biggest party trick. We'll return to this idea and see how it further enhances usability and security later. For now, let's move on to operability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Certificate authentication improves operability
&lt;/h3&gt;

&lt;p&gt;Eliminating key approval and distribution has immediate operational benefits. You're no longer wasting ops cycles on mundane key management tasks, and you eliminate any ongoing costs associated with monitoring and maintaining homegrown machinery for adding, removing, synchronizing, and auditing static public key files across your fleet.&lt;/p&gt;

&lt;p&gt;The ability to issue SSH user certificates via a variety of authentication mechanisms also facilitates operational automation. If a cron job or script needs SSH access it can obtain an ephemeral SSH certificate automatically, when it's needed, instead of being pre-provisioned with a long-lived, static private key.&lt;/p&gt;

&lt;p&gt;SSH public key authentication introduces some weird operational constraints around host names that certificate authentication eliminates. As we've seen, when an SSH client connects to a host for the first time it displays a TOFU warning to the user. When the user types "yes" the host's public key is added locally to &lt;code&gt;~/.ssh/known_hosts&lt;/code&gt;. This binding between the host name and a specific public key is &lt;em&gt;permanent&lt;/em&gt;. If the host presents a different public key later, the user gets an even scarier &lt;em&gt;host key verification failure&lt;/em&gt; error message that looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh ubuntu@ec2-54-161-77-102.compute-1.amazonaws.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 ECDSA key sent by the remote host is
SHA256:2ae53QcOB0W6HO+XtPmMXk7To/MvMuhFxTj8ZD7eSsE.
Please contact your system administrator.
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in ~/.ssh/known_hosts:11
ECDSA host key for ec2-54-161-77-102.compute-1.amazonaws.com has changed and you have requested strict checking.
Host key verification failed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This makes it operationally challenging to reuse host names. If &lt;code&gt;prod01.example.com&lt;/code&gt; has a hardware failure, and it's replaced with a new host using the same name, host key verification failures will ensue. This usually results in a bunch engineers contacting secops to tell them they're being hacked.&lt;/p&gt;

&lt;p&gt;Ignoring host key verification failures has the exact same attack surface area as not knowing the key at all. Curiously, OpenSSH chooses to soft-fail with an easily bypassed prompt when the key isn't known (TOFU), but hard-fails with a much scarier and harder to bypass error when there's a mismatch.&lt;/p&gt;

&lt;p&gt;In any case, certificates fix all of this since a current name-to-public-key binding is communicated when a connection is established. Changing the host's public key is fine, as long as the host also gets a new certificate. You can safely reuse host names and even run multiple hosts with the same name. You'll never see a host key verification failure again. Beyond name reuse, we'll soon see that eliminating host key verification failures is one of the many ways certificate authentication facilitates good security hygiene.&lt;/p&gt;

&lt;h3&gt;
  
  
  Certificate authentication improves security
&lt;/h3&gt;

&lt;p&gt;While the SSH protocol itself is secure, public key authentication encourages a bunch of bad security practices and makes good security hygiene hard to achieve.&lt;/p&gt;

&lt;p&gt;With public key authentication, keys are trusted permanently. A compromised private key or illegitimate key binding may go unnoticed or unreported for a long time. Key management oversight (e.g., forgetting to remove an ex-employee's public keys from hosts) results in SSH failing open: unauthorized access without end.&lt;/p&gt;

&lt;p&gt;Certificates, on the other hand, expire. In an incident — a mistake, theft, misuse, or key exfiltration of any form — compromised SSH credentials will expire automatically, without intervention, even if the incident goes unnoticed or unreported. &lt;strong&gt;SSH certificates are fail-secure.&lt;/strong&gt; Access expires naturally if no action is taken to extend it. And when SSH users and hosts check in periodically with your CA to renew their credentials, a complete audit record is produced as a byproduct.&lt;/p&gt;

&lt;p&gt;We've already seen how public key authentication trains users to ignore serious security warnings (TOFU) and triggers spurious security errors. This is more than an operational nuisance. Confusion caused by host key verification failure discourages host rekeying (i.e., replacing a host's key pair). Host private keys aren't very well protected, so periodic rekeying is good practice. Rekeying may be required after a breach or after offboarding a user. But, to avoid disruption from ensuing host key verification failures, it's often not done. Certificate authentication makes rekeying hosts trivial.&lt;/p&gt;

&lt;p&gt;Public key authentication also makes rekeying difficult for users. Key approval and distribution is annoying enough that users are reluctant to rekey, even if you've built tools to make it possible. Worse, frustrated users copy private keys and reuse them across devices, often for many years. Key reuse is a serious security sin. Private keys are &lt;em&gt;never&lt;/em&gt; supposed to be transferred across a network. But SSH public key authentication exposes users directly to sensitive private keys, then fails to give them usable tools for key management. It's a recipe for misuse and abuse.&lt;/p&gt;

&lt;p&gt;An SSH CA, coupled with a simple command-line client for users, can streamline key generation and insulate users from a lot of unnecessary detail. Certificate authentication can't completely eliminate all security risks, but it does facilitate SSH workflows that are more intuitive, easier to use, and harder to misuse.&lt;/p&gt;

&lt;p&gt;To learn more about SSH certificates visit &lt;a href="https://smallstep.com/sso-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;the Smallstep website&lt;/a&gt;. You can even try our free hosted offering and experience the value of SSH certificates in under five minutes!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>security</category>
      <category>opensource</category>
      <category>sre</category>
    </item>
    <item>
      <title>If you’re not using SSH certificates you’re doing SSH wrong | Episode 1: Keys versus Certificates</title>
      <dc:creator>Cass Fultz</dc:creator>
      <pubDate>Fri, 21 Aug 2020 18:51:11 +0000</pubDate>
      <link>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-1-keys-versus-certificates-5a0n</link>
      <guid>https://forem.com/smallstep/if-you-re-not-using-ssh-certificates-you-re-doing-ssh-wrong-episode-1-keys-versus-certificates-5a0n</guid>
      <description>&lt;p&gt;SSH is ubiquitous. It's the de-facto solution for remote administration of *nix systems. But SSH has some pretty gnarly issues when it comes to usability, operability, and security.&lt;/p&gt;

&lt;p&gt;You're probably familiar with these issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSH user experience is terrible.&lt;/strong&gt; SSH user on-boarding is slow and manual. Connecting to new hosts produces confusing security warnings. You're left with weird new credentials to manage with little guidance on how to do so.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operating SSH at scale is a disaster.&lt;/strong&gt; Key approval &amp;amp; distribution is a silly waste of time. Host names can't be reused. Homegrown tools scatter key material across your fleet that must be cleaned up later to off-board users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSH encourages bad security practices.&lt;/strong&gt; Rekeying is hard, so it's not done. Users are exposed to key material and encouraged to reuse keys across devices. Keys are trusted permanently, so mistakes are fail-open.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The good news is this is all easy to fix.&lt;/p&gt;

&lt;p&gt;None of these issues are actually inherent to SSH. They're actually problems with SSH &lt;em&gt;public key authentication&lt;/em&gt;. The solution is to switch to &lt;em&gt;certificate authentication&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSH certificate authentication makes SSH easier to use, easier to operate, and more secure.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;At smallstep, certificates are kind of our jam. We build open source software that lets you run your own private certificate authority and manage X.509 (TLS/HTTPS) certificates.&lt;/p&gt;

&lt;p&gt;SSH certificates have been on our radar for a while. From our perspective they're all pros, no cons. But no one uses them. Why not? We've asked hundreds of people that question. Here's what we found out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;People do use SSH certificates. In fact, pretty much &lt;em&gt;everyone&lt;/em&gt; operating at scale that knows what they're doing does (&lt;a href="https://engineering.fb.com/security/scalable-and-secure-access-with-ssh/" rel="noopener noreferrer"&gt;Facebook&lt;/a&gt;, &lt;a href="https://medium.com/uber-security-privacy/introducing-the-uber-ssh-certificate-authority-4f840839c5cc" rel="noopener noreferrer"&gt;Uber&lt;/a&gt;, Google, &lt;a href="https://github.com/Netflix/bless" rel="noopener noreferrer"&gt;Netflix&lt;/a&gt;, &lt;a href="https://www.usenix.org/conference/srecon17europe/program/presentation/sheridan" rel="noopener noreferrer"&gt;Intercom&lt;/a&gt;, &lt;a href="https://eng.lyft.com/blessing-your-ssh-at-lyft-a1b38f81629d" rel="noopener noreferrer"&gt;Lyft&lt;/a&gt;, etc), but...&lt;/li&gt;
&lt;li&gt;Certificates and public key infrastructure (PKI) are hard to grok. People don't immediately understand the benefits.&lt;/li&gt;
&lt;li&gt;There's a (small) tooling gap that exacerbates this knowledge gap. It's not hard to fill, but people are wary to do so themselves without a deeper understanding of PKI concepts.&lt;/li&gt;
&lt;li&gt;More than anything, SSH certificates haven't gotten the press they deserve. &lt;em&gt;Most&lt;/em&gt; people we asked hadn't heard of them at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We're convinced that SSH certificates are the right way to do SSH. They're not that hard to understand, and it's well worth the effort. SSH certificates deserve more press, and broader use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwoxajsge4cw3iorfpgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwoxajsge4cw3iorfpgw.png" alt="why don't more people know about ssh certificates?" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Public key authentication
&lt;/h2&gt;

&lt;p&gt;Most SSH deployments use &lt;em&gt;public key authentication&lt;/em&gt;, which uses asymmetric (public key) cryptography with a public / private key pair generated for each user &amp;amp; host to authenticate.&lt;/p&gt;

&lt;p&gt;The magic of asymmetric cryptography is the special correspondence between a public and private key. You can &lt;em&gt;sign&lt;/em&gt; data with your private key and someone else can &lt;em&gt;verify&lt;/em&gt; your signature with the corresponding public key. Like a hash, it's computationally infeasible to forge a signature. Thus, if you can verify a signature, and you know who owns the private key, you know who generated the signature.&lt;/p&gt;

&lt;p&gt;Simple authentication can be implemented by challenging someone to sign a big random number. If I open a socket to you and send a random number, and you respond with a valid signature over that number, I must be talking to you.&lt;/p&gt;

&lt;p&gt;This is an oversimplification, but it's more or less how SSH public key authentication works. Certificate authentication works the same way, but with an important twist that we'll get to in a moment.&lt;/p&gt;

&lt;p&gt;To SSH to a host using public key authentication the host needs to know your public key. By default, your public key must be added to &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt;. Maintaining this file for every user across a fleet is operationally challenging and error prone.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fymdmauvj3gv8cq6g643i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fymdmauvj3gv8cq6g643i.png" alt="SSH Deployment Rube Goldberg Machine" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SSH user onboarding with public key authentication usually starts with some baroque incantation of &lt;code&gt;ssh-keygen&lt;/code&gt;, hopefully pulled from a runbook, but more likely cribbed from stack overflow. Next you'll be asked to submit your public key for &lt;em&gt;approval and distribution&lt;/em&gt;. This process is typically manual and opaque. You might be asked to email an administrator or open a JIRA ticket. Then you wait. While you're doing that, some poor operator gets interrupted and told to add your key to a manifest in some repo and trigger a deploy. Once that's done you can SSH. Since key bindings are permanent, your SSH access will continue in perpetuity until someone reverses this process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Certificate authentication
&lt;/h2&gt;

&lt;p&gt;Certificate authentication eliminates key approval and distribution. Instead of scattering public keys across static files, you bind a public key to a name with a &lt;em&gt;certificate&lt;/em&gt;. A certificate is just a data structure that includes a public key, name, and ancillary data like an expiration date and permissions. The data structure is signed by a &lt;em&gt;certificate authority&lt;/em&gt; (CA).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ssh-keygen -L -f id_ecdsa-cert.pub
id_ecdsa-cert.pub:
        Type: ecdsa-sha2-nistp256-cert-v01@openssh.com user certificate
        Public key: ECDSA-CERT SHA256:O6M6oIjDm5gPm1/aTY619BgC3KSpS4c3aHVWxYh/uGQ
        Signing CA: ECDSA SHA256:EY2EXJGoPv2LA6yEbjH+sf9JjG9Rd45FH1Wt/6H1k7Y
        Key ID: "mike@example.com"
        Serial: 4309995459650363134
        Valid: from 2019-09-11T14:50:01 to 2019-09-11T18:50:01
        Principals:
                mike
        Critical Options: (none)
        Extensions:
                permit-X11-forwarding
                permit-agent-forwarding
                permit-port-forwarding
                permit-pty
                permit-user-rc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To enable certificate authentication simply configure clients and hosts to trust any certificates signed by your CA's public key.&lt;/p&gt;

&lt;p&gt;On each host, edit &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt;, specifying the CA public key for verifying user certificates, the host's private key, and the host's certificate:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Path to the CA public key for verifying user certificates
TrustedUserCAKeys /etc/ssh/ssh_user_key.pub

# Path to this host's private key and certificate
HostKey /etc/ssh/ssh_host_ecdsa_key
HostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On each client, add a line to &lt;code&gt;~/.ssh/known_hosts&lt;/code&gt; specifying the CA public key for verifying host certificates:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@cert-authority *.example.com ecdsa-sha2-nistp256 AAAAE...=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's it. That's literally all that you need to do to start using certificate authentication. You can even use it alongside public key authentication to make transitioning easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrpq5s3ygi0prmcrnkl8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrpq5s3ygi0prmcrnkl8.png" alt="SSH Certificate Authentication - Example Architecture" width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Static keys in &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; are no longer needed. Instead, peers learn one another's public keys on demand, when connections are established, by exchanging certificates. Once certificates have been exchanged the protocol proceeds as it would with public key authentication.&lt;/p&gt;

&lt;p&gt;To learn more about SSH certificates visit &lt;a href="https://smallstep.com/sso-ssh?utm_campaign=Dev.to&amp;amp;utm_source=dev.to"&gt;the Smallstep website&lt;/a&gt;. You can even try our free hosted offering and experience the value of SSH certificates in under five minutes!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>security</category>
      <category>opensource</category>
      <category>sre</category>
    </item>
  </channel>
</rss>
