> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SSL and TLS Basics

> Explains SSL/TLS certificate fundamentals, asymmetric and symmetric cryptography, trust establishment, certificate lifecycle, and practical SSH and HTTPS configuration to secure communications.

Hello — this lesson explains the fundamentals of SSL/TLS certificates: what they are, why they matter, and how to configure certificates to secure SSH and HTTPS services. We'll cover the roles of asymmetric and symmetric cryptography, how certificates establish trust, and the lifecycle from key generation to certificate validation.

A certificate (in this context) establishes trust between two parties during a transaction. For example, when a user connects to a web server, TLS certificates make sure the communication is encrypted and that the server is actually who it claims to be.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/user-server-authenticated-connection.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=79ba6bcd84c9e411a4c6aa7fc8831da7" alt="A simple diagram showing a blue user icon on the left and a purple server tower on the right connected by a green line with a handshake icon in the center. A certificate symbol above the handshake suggests a trusted or authenticated connection." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/user-server-authenticated-connection.jpg" />
</Frame>

Why encryption matters
Without secure connectivity, sensitive data (credentials, payment details) could be transmitted in plain text and intercepted by attackers. Encryption protects data in transit by transforming readable data into ciphertext that is useless without the correct key.

Basic cryptography modes

* Symmetric encryption: same key encrypts and decrypts data. Fast and efficient, but requires a secure method to share the key.
* Asymmetric encryption (public-key cryptography): uses a key pair — a private key (kept secret) and a public key (shared). One key encrypts and the other decrypts, removing the need to transmit a shared secret.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/symmetric-encryption-key-box.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=b0c14dd42fb39bed3b6697011808e87b" alt="A white rectangular box with a green key icon and the words &#x22;SYMMETRIC ENCRYPTION&#x22; in bold black text. The box has a thin green border and sits on a pale background." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/symmetric-encryption-key-box.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/asymmetric-encryption-private-public-keys.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=749e3e8bc76d1eb0c778d8bdf530c057" alt="A simple diagram titled &#x22;ASYMMETRIC ENCRYPTION&#x22; with a green key icon on the left labeled &#x22;Private Key&#x22; and a green padlock icon on the right labeled &#x22;Public Key.&#x22;" width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/asymmetric-encryption-private-public-keys.jpg" />
</Frame>

Analogy: public key = lock anyone can use to secure a message; private key = the single key that opens what the lock protects. The private key must always remain confidential.

SSH key-based authentication — a practical asymmetric example
Generate an SSH key pair locally and copy the public key to the server:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ssh-public-private-key-diagram.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=761bf0bf4ba31a29e34267befcba4236" alt="A diagram titled &#x22;Asymmetric Encryption - SSH&#x22; showing user icons with private keys and corresponding public locks connecting to locked server icons. It illustrates SSH public/private key authentication." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ssh-public-private-key-diagram.jpg" />
</Frame>

Example SSH workflow (commands and notes):

```bash theme={null}
# Generate an SSH key pair (RSA example)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa

# Files created:
#  ~/.ssh/id_rsa        (private key - keep this secret)
# On the server: append the public key to the user's authorized_keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

# Use the private key to SSH into the server
ssh -i ~/.ssh/id_rsa user1@server1
```

<Callout icon="lightbulb" color="#1CB2FE">
  Consider newer key types: `ed25519` keys are recommended for new SSH key pairs due to stronger security and better performance compared to older RSA keys. Example: `ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519`.
</Callout>

TLS for HTTPS: combining asymmetric + symmetric cryptography
TLS uses both cryptography types:

* Use asymmetric cryptography (public/private keys) to securely agree on a symmetric session key.
* Use symmetric encryption for the bulk of the session because it's faster.

A server typically has a private/public key pair and a certificate containing the server's public key and identifying details. Browsers obtain that certificate when establishing an HTTPS connection.

Example of a server private key (PEM format):

```pem theme={null}
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAABKBgQDkwiLGQAgAN1HpEoLUaqKYiYJIk9wetzotW2/w4nsGhonuWGrT
d7+823xd8FDH+WJLqXsTDkrpKNG3sh67dHRGGipKcEXfZnzT5yDyK/jA6uQvAzl+
I4xNNqtwKDC03uoLpnMEsayPhNtexosfScu1KXeOL6/nTkn9Gc/YoUWzgQIDAQAB
AoGBAOJF6VHCGmfkUGBD0Cc+hzBsq/MQVnYHhUNCM7rIuzocMCkTSi98PqsXS7A7
uhvj4MfIj5WsyIpStwaF6IIxUaP6afrn1KwJ9jZ5bJ9iy0UdYTd3Kk7fOjjkKLK+u
eOk1XibMPLLAXtig7aOvjhg5CmSuhByFc0LRbF8E9l4JOAHBAkEA/ye3prO/ho/8
PhXWc9n+L10cH+FaH4z5peUULNy/xRf1WstV5WCgasvJgtbr7r9p5u4flxS4621/
jNwp8X8sKQJBAOWECwzFLs/GvWZ5H3UV7UoSo6o0QccfKJsQGvGJK0T8rWr8M4vq
h5PDUtoPAcc4Gzgz8BzBbFQ2nmzy10x7t5kCQAQndmL9bDHZqEauflZWhz/oKsWp
tDLtTac4ypJMacbgs/rtcpGQeCwk8zvxGdhCP4w19le0W6phlwEI/YJUCrkCQHgH
wEejb8HV7AOFYMA5AWn1qYYsApaCYxgFKjIbThe9tWv4DXUk6FaM1e3YX1OysfmI
oBBJz7+S+PN9ZL9pDDECQDePUNHDilLyngKMVFj09iRv6YKUc197c4pUseqDr8dx
iyzzypU7eM5pSSDoosysD5iqIcXbdh+j0LKEtGs4vdQ=
-----END RSA PRIVATE KEY-----
```

High-level RSA-style key-exchange flow (illustrative)

1. Browser connects to `https://my-bank.com`.
2. Server sends its certificate (includes the server public key and identity).
3. Browser verifies the certificate (domain, CA signature, validity).
4. Browser encrypts a symmetric session key with the server’s public key and sends it.
5. Server decrypts the session key with its private key.
6. Both use the symmetric key for the session.

Note: Modern TLS commonly uses ephemeral Diffie–Hellman (for example, ECDHE) to provide forward secrecy. In ECDHE, the certificate authenticates the server but the session key is agreed via the key-agreement protocol rather than being directly encrypted with the server's public key.

<Callout icon="warning" color="#FF6B6B">
  Never expose private keys. If a private key is leaked, attackers can impersonate your server or decrypt traffic. Store private keys securely (use HSMs, encrypted key storage, or restricted file permissions).
</Callout>

Realistic attack example (phishing + fake certificate)
An attacker could host a replica of your bank’s website and terminate HTTPS with their own certificate. The connection between the browser and the malicious server is encrypted, but the attacker still receives your credentials because you connected to their site. This is why certificate validation and CA trust matter.

How browsers validate certificates
Browsers do more than accept a public key; they validate a digital certificate that contains identifying info (subject/CN and SANs) and a digital signature from a Certificate Authority (CA). Validation steps include:

* Confirm the certificate’s subject or Subject Alternative Names match the URL.
* Verify the certificate’s signature using the issuing CA’s public key.
* Check validity dates and, where applicable, revocation status (CRL/OCSP).

If a certificate is self-signed or signed by an unknown CA, the browser will warn the user.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/my-bank-ssl-error-not-private.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=f61304dce520602832fc3fe7922cdb3e" alt="A web browser displays a security warning page saying &#x22;Your connection is not private&#x22; with a red padlock and a &#x22;Not secure&#x22; notice beside the URL (https://my-bank.com). The page indicates an invalid SSL certificate error (NET::ERR_CERT_AUTHORITY_INVALID)." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/my-bank-ssl-error-not-private.jpg" />
</Frame>

Certificate Authorities (CAs) and requesting trusted certificates
To get a certificate that browsers trust, use a CA. The CA validates your domain ownership and (depending on the validation level) your organization, then signs a certificate that chains to a trusted root in browser/OS trust stores. Popular public CAs include [DigiCert](https://www.digicert.com), [GlobalSign](https://www.globalsign.com), and others.

Generate a CSR (Certificate Signing Request) with OpenSSL:

```bash theme={null}
# Generate a private key
openssl genrsa -out my-bank.key 2048

# Generate a CSR using that key (non-interactive subject example)
openssl req -new -key my-bank.key -out my-bank.csr -subj "/C=US/ST=CA/O=MyOrg\\, Inc./CN=my-bank.com"
```

Send `my-bank.csr` to the CA. After validation, the CA issues a signed certificate that your users’ browsers will trust because the CA’s root certificate is included in their trust stores.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ssl-bank-padlock-certificate-ca-keys.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=71245e16fe2bcec51fa049a27431adfc" alt="An infographic about SSL/TLS certificates showing a browser with an online banking site and padlock on the left and a framed certificate for &#x22;my-bank.com&#x22; on the right. Across the top are certificate authority logos (e.g., Symantec, GlobalSign, DigiCert) and key icons representing issued keys." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ssl-bank-padlock-certificate-ca-keys.jpg" />
</Frame>

Private/internal CAs
For internal services you can run a private CA and install the CA root certificate into employee devices so certificates signed by your private CA are trusted within your organization.

TLS handshake summary (simplified)

1. Client connects to `https://example.com`.
2. Server sends its certificate (server public key + identity).
3. Client verifies the certificate (domain match, CA signature, validity).
4. Client and server agree on or exchange a symmetric session key (often via ECDHE for forward secrecy).
5. Client and server use symmetric encryption for application data.
6. The CA’s root public key (in the client trust store) validates the server certificate signature.

Client certificates
TLS can also authenticate clients: during the handshake the server requests a client certificate and validates it. Client certificates are common in high-security or enterprise environments but rare on public consumer websites.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ca-workflow-client-serving-certs-attacker.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=2d81fc8805608418d996f07385967f43" alt="An infographic diagram showing a Certificate Authority (CA) workflow with client and serving certificates. It includes icons of locks, keys, users, a server, the Symantec logo, and a masked attacker figure in the center." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/ca-workflow-client-serving-certs-attacker.jpg" />
</Frame>

Public Key Infrastructure (PKI)
The ecosystem that manages keys, certificates, issuance, revocation, and trust is called Public Key Infrastructure (PKI). PKI combines technology, processes, and people to maintain secure certificate lifecycles.

Clarifying the lock/key roles

* Signing with a private key allows anyone with the public key to verify authenticity (digital signatures).
* Encrypting with a public key ensures only the private key holder can decrypt (confidentiality).

Keep private keys private — compromise leads to impersonation and decryption risks.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/rnd3uk1XQ7oH3ZT8/images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/public-private-key-icons.jpg?fit=max&auto=format&n=rnd3uk1XQ7oH3ZT8&q=85&s=9e4f0fd4b1ccb6a22d39211ef30c7be5" alt="The image shows two orange icons on a pale background: a padlock on the left labeled &#x22;Public Key (Lock)&#x22; and a key on the right labeled &#x22;Private Key.&#x22; It visually represents the public/private key concept used in cryptography." width="1920" height="1080" data-path="images/DevOps-Pre-Requisite-Course/Security/SSL-and-TLS-Basics/public-private-key-icons.jpg" />
</Frame>

Common naming conventions and file extensions
Use these as a quick reference. Filenames containing the word “key” or extension `.key` usually indicate private keys. Certificates and public keys commonly use `.crt` or `.pem`.

| Resource Type | Typical Extensions | Examples |
| -: | -: | - |
| Certificate / Public Key | `.crt`, `.pem` | `server.crt`, `server.pem`, `client.crt` |
| Private Key | `.key`, `-key.pem` | `server.key`, `server-key.pem`, `client.key` |

Further reading and references

* OpenSSL: [https://www.openssl.org](https://www.openssl.org)
* DigiCert: [https://www.digicert.com](https://www.digicert.com)
* GlobalSign: [https://www.globalsign.com](https://www.globalsign.com)
* TLS overview: [https://datatracker.ietf.org/wg/tls/about/](https://datatracker.ietf.org/wg/tls/about/)

That concludes this lesson on SSL/TLS basics: asymmetric vs symmetric cryptography, certificate authorities, certificate validation in browsers, and practical examples for SSH and HTTPS. Thank you for reading.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/devops-pre-requisite-course/module/078af284-cd5c-4557-81ee-73e680b8f300/lesson/a9b52f6d-c4e5-4440-9ec4-123d110efabc" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/devops-pre-requisite-course/module/078af284-cd5c-4557-81ee-73e680b8f300/lesson/8d1bb779-6950-45f3-95cb-53dbec22885d" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.