<?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>DEV Community: Shreya_1187</title>
    <description>The latest articles on DEV Community by Shreya_1187 (@shreya_1187_e79a860da272c).</description>
    <link>https://dev.to/shreya_1187_e79a860da272c</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4273532%2Fd1c35035-ae0d-4c71-b154-1e4b4dd3d992.png</url>
      <title>DEV Community: Shreya_1187</title>
      <link>https://dev.to/shreya_1187_e79a860da272c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shreya_1187_e79a860da272c"/>
    <language>en</language>
    <item>
      <title>Inside SSH: The Cryptography Behind Secure Authentication</title>
      <dc:creator>Shreya_1187</dc:creator>
      <pubDate>Mon, 30 Nov 2026 07:52:24 +0000</pubDate>
      <link>https://dev.to/shreya_1187_e79a860da272c/inside-ssh-the-cryptography-behind-secure-authentication-1j2n</link>
      <guid>https://dev.to/shreya_1187_e79a860da272c/inside-ssh-the-cryptography-behind-secure-authentication-1j2n</guid>
      <description>&lt;p&gt;While learning Linux and exploring SSH, I came across something that caught my attention: &lt;strong&gt;Cryptographic Authentication&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We've been using different forms of authentication for decades like passwords, PINs, OTPs, biometrics, and so on. But SSH introduced me to another interesting approach: authenticating using cryptographic key pairs.&lt;/p&gt;

&lt;p&gt;I'd heard about public and private keys before, but I wanted to understand what actually happens behind the scenes when we authenticate ourselves using them.&lt;/p&gt;

&lt;p&gt;So, let's break it down!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. First, what exactly is SSH?
&lt;/h2&gt;

&lt;p&gt;SSH (Secure Shell) is a network protocol that allows us to securely communicate with and remotely access another machine over an unsecured network.&lt;/p&gt;

&lt;p&gt;For example, imagine you have your local machine and a remote Linux server. You want to access that server, execute commands, manage files, or deploy an application without physically accessing it.&lt;/p&gt;

&lt;p&gt;That's where SSH comes in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh username@server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This establishes a secure connection between your local machine (client) and the remote machine (server).&lt;/p&gt;

&lt;p&gt;But before allowing access, the server needs to authenticate you. Similarly, your client also needs to verify that it's connecting to the genuine server.&lt;/p&gt;

&lt;p&gt;Traditionally, client authentication could be done using a username and password.&lt;/p&gt;

&lt;p&gt;However, there's another approach: &lt;strong&gt;Public Key Authentication.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Why do we need SSH keys?
&lt;/h2&gt;

&lt;p&gt;Let's talk about password-based authentication first.&lt;/p&gt;

&lt;p&gt;You enter your password, and the server verifies whether it matches the expected credentials.&lt;/p&gt;

&lt;p&gt;Although SSH encrypts the communication channel, password-based authentication still has certain limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Weak or reused passwords.&lt;/li&gt;
&lt;li&gt;Password guessing and brute-force attempts.&lt;/li&gt;
&lt;li&gt;Password theft through phishing or compromised systems.&lt;/li&gt;
&lt;li&gt;Managing credentials across multiple servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of repeatedly relying on passwords, SSH supports authentication using cryptographic key pairs.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdgch380nteek5kv0qqsv.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdgch380nteek5kv0qqsv.png" alt="SSH key-based authentication illustration" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is where asymmetric cryptography comes into the picture.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A little cryptography: Symmetric vs Asymmetric Encryption
&lt;/h2&gt;

&lt;p&gt;Before understanding SSH key authentication, let's understand two fundamental cryptographic concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Symmetric Cryptography
&lt;/h3&gt;

&lt;p&gt;In symmetric cryptography, the same secret key is used for both encryption and decryption.&lt;/p&gt;

&lt;p&gt;Imagine having a locked box and a key.&lt;/p&gt;

&lt;p&gt;You use that key to lock the box, and the receiver uses the same key to unlock it.&lt;/p&gt;

&lt;p&gt;Both parties must securely possess the same secret key.&lt;/p&gt;

&lt;p&gt;Some examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AES (Advanced Encryption Standard)&lt;/li&gt;
&lt;li&gt;ChaCha20&lt;/li&gt;
&lt;/ul&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk12x90vw1tfhznr9fdro.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk12x90vw1tfhznr9fdro.png" alt="Symmetric encryption illustration" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Asymmetric Cryptography
&lt;/h3&gt;

&lt;p&gt;Asymmetric cryptography works differently.&lt;/p&gt;

&lt;p&gt;It uses a pair of mathematically related keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public Key:&lt;/strong&gt; Can be shared with others.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private Key:&lt;/strong&gt; Must remain secret with its owner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These keys are mathematically related, but knowing the public key does not practically allow someone to derive the private key.&lt;/p&gt;

&lt;p&gt;One important application of asymmetric cryptography is digital signatures.&lt;/p&gt;

&lt;p&gt;For example, you can use your private key to create a digital signature, and someone else can use your corresponding public key to verify that signature.&lt;/p&gt;

&lt;p&gt;Some examples of asymmetric cryptographic algorithms include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RSA&lt;/li&gt;
&lt;li&gt;Ed25519&lt;/li&gt;
&lt;li&gt;ECDSA&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Here's an interesting distinction:&lt;/strong&gt; SSH uses asymmetric cryptography for authentication, but it also uses symmetric cryptography to encrypt the actual communication after establishing the connection.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because symmetric encryption is generally much more efficient for encrypting large amounts of data.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Public and Private Keys: How do they work together?
&lt;/h2&gt;

&lt;p&gt;Let's take a simple example.&lt;/p&gt;

&lt;p&gt;Imagine &lt;strong&gt;A&lt;/strong&gt; wants to authenticate herself to a remote server.&lt;/p&gt;

&lt;p&gt;She generates a pair of keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             A's Key Pair

          ┌──────────────────┐
          │                  │
          │    Public Key    │
          │                  │
          │    Private Key   │
          │                  │
          └──────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The public key can be shared with the server, while the private key stays safely on &lt;strong&gt;A&lt;/strong&gt;'s machine.&lt;/p&gt;

&lt;p&gt;Now, here's the interesting part.&lt;/p&gt;

&lt;p&gt;The server doesn't need &lt;strong&gt;A&lt;/strong&gt;'s private key to verify her identity.&lt;/p&gt;

&lt;p&gt;Instead, &lt;strong&gt;A&lt;/strong&gt; uses her private key to create a digital signature.&lt;/p&gt;

&lt;p&gt;The server then uses &lt;strong&gt;A&lt;/strong&gt;'s public key to verify that signature.&lt;/p&gt;

&lt;p&gt;If verification succeeds, the server gets cryptographic proof that the client possesses the corresponding private key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The private key never needs to leave A's machine.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the fundamental idea behind public-key authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What actually happens during SSH authentication?
&lt;/h2&gt;

&lt;p&gt;Let's say you're connecting from your local machine to a remote Linux server using SSH keys.&lt;/p&gt;

&lt;p&gt;Here's what happens at a high level:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Key generation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You generate a public-private key pair on your local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Public key registration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You copy your public key to the remote server and add it to the user's &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: SSH connection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You initiate an SSH connection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh username@server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Authentication request&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your SSH client tells the server that it wants to authenticate using a particular public key.&lt;/p&gt;

&lt;p&gt;The server checks whether that public key is authorized for the requested account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Digital signature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The client proves that it possesses the corresponding private key by creating a digital signature over data associated with the SSH connection and authentication request.&lt;/p&gt;

&lt;p&gt;The private key stays on the client machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Signature verification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The server uses the registered public key to verify the signature.&lt;/p&gt;

&lt;p&gt;If the signature is valid and the key is authorized, authentication succeeds.&lt;/p&gt;

&lt;p&gt;You get access to the remote machine!&lt;/p&gt;

&lt;h3&gt;
  
  
  But where does hashing come into the picture?
&lt;/h3&gt;

&lt;p&gt;This was another interesting part for me.&lt;/p&gt;

&lt;p&gt;Digital signatures generally involve cryptographic hash functions.&lt;/p&gt;

&lt;p&gt;A hash function takes input data and produces a fixed-length digest.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input Data
    |
    v
Hash Function
    |
    v
Fixed-length Digest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The signing algorithm uses the private key to produce a signature associated with the message or its digest.&lt;/p&gt;

&lt;p&gt;The verification algorithm uses the corresponding public key to check that signature.&lt;/p&gt;

&lt;p&gt;One important clarification: the server isn't simply comparing a hash generated from the public key with a hash generated from the private key.&lt;/p&gt;

&lt;p&gt;It's verifying a cryptographic signature using the mathematical relationship between the key pair.&lt;/p&gt;

&lt;p&gt;The exact signing and verification process depends on the algorithm being used.&lt;/p&gt;

&lt;p&gt;That's what makes the process interesting!&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Let's implement it ourselves!
&lt;/h2&gt;

&lt;p&gt;Understanding the theory is one thing. Actually implementing it between two machines makes everything much clearer.&lt;/p&gt;

&lt;p&gt;Let's assume:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Machine A: Your local Linux machine (SSH client).&lt;/li&gt;
&lt;li&gt;Machine B: A remote Linux machine (SSH server).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Generate an SSH key pair
&lt;/h3&gt;

&lt;p&gt;On Machine A, execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C &lt;span class="s2"&gt;"your-email@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates two files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;id_ed25519&lt;/code&gt; → Private key.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;id_ed25519.pub&lt;/code&gt; → Public key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the private key secure. Never share or upload it.&lt;/p&gt;

&lt;p&gt;You can also protect your private key with a passphrase.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Copy the public key to the remote server
&lt;/h3&gt;

&lt;p&gt;If &lt;code&gt;ssh-copy-id&lt;/code&gt; is available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-copy-id username@server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This installs your public key into the remote user's &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Alternatively, you can manually append the contents of your &lt;code&gt;.pub&lt;/code&gt; file to that file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Connect using SSH
&lt;/h3&gt;

&lt;p&gt;Now try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh username@server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is configured correctly, you should be able to authenticate using your SSH key instead of entering your account password.&lt;/p&gt;

&lt;p&gt;You can also use verbose mode to inspect what's happening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh -v username@server_ip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is particularly useful for understanding and debugging SSH authentication.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7gf7fxo2srx02lktniqz.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7gf7fxo2srx02lktniqz.png" alt="SSH key authentication terminal demonstration" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Where else did I use this?
&lt;/h2&gt;

&lt;p&gt;After experimenting with SSH authentication between machines, I encountered the same concept again while working with AWS EC2 and GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS EC2
&lt;/h3&gt;

&lt;p&gt;When launching an EC2 instance, AWS allows you to create or select a key pair.&lt;/p&gt;

&lt;p&gt;You download the private key (&lt;code&gt;.pem&lt;/code&gt;) and use it from your local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh -i my-key.pem ubuntu@EC2_PUBLIC_IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The corresponding public key is configured on the instance, allowing you to authenticate without sharing your private key with the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub SSH Authentication
&lt;/h3&gt;

&lt;p&gt;I also used SSH keys to authenticate with GitHub when cloning repositories.&lt;/p&gt;

&lt;p&gt;Instead of using HTTPS credentials, you can register your public SSH key with your GitHub account.&lt;/p&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github.com:username/repository.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub verifies your identity using the corresponding public key.&lt;/p&gt;

&lt;p&gt;This was another practical example that helped me understand how the same underlying cryptographic idea is used across different systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. A few things worth remembering
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Never share your private key with anyone.&lt;/li&gt;
&lt;li&gt;Never commit private keys to GitHub or expose them in public repositories.&lt;/li&gt;
&lt;li&gt;Use a passphrase to protect your private key where appropriate.&lt;/li&gt;
&lt;li&gt;Verify server host keys instead of blindly accepting unknown ones.&lt;/li&gt;
&lt;li&gt;Keep your SSH server configuration and authorized keys properly managed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your public key is meant to be shared. Your private key is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;What started as curiosity while learning Linux turned into a much more interesting exploration of cryptography, digital signatures and secure authentication.&lt;/p&gt;

&lt;p&gt;I initially thought SSH key authentication was simply about generating two keys and connecting to a remote server.&lt;/p&gt;

&lt;p&gt;But understanding how the client proves ownership of a private key without actually sending it to the server made the whole mechanism much more fascinating.&lt;/p&gt;

&lt;p&gt;There's still a lot more to explore in cryptography if we go deeper into it; hashing algorithms, digital signature creation, and the mathematics behind public-private key verification.&lt;/p&gt;

&lt;p&gt;I'll probably explore those concepts in more detail as I learn more.&lt;/p&gt;

&lt;p&gt;But for now, that was my exploration of what happens behind the scenes of cryptographic authentication!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sometimes, understanding what happens behind a simple command makes you appreciate the engineering underneath it.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>backend</category>
      <category>networking</category>
      <category>cryptography</category>
    </item>
  </channel>
</rss>
