# A Guide to Server Security with Passwordless Authentication

## Passwordless Authentication Between Servers: A Step Toward DevOps Mastery

Embarking on the DevOps journey means diving into automation, security, and efficiency—principles that drive the seamless functioning of modern IT infrastructure. One of the core skills that DevOps engineers leverage every day is passwordless SSH authentication. By automating secure, password-free connections between servers, we open the door to countless automations and streamline deployments across multiple environments. This guide isn’t just about achieving a technical outcome; it’s about adopting a DevOps mindset of efficiency and continual growth.

---

### Why Passwordless Authentication?

The ability to connect servers without entering a password is key to creating a secure, automated, and efficient workflow. This setup lays the foundation for automated deployments, server management, and cross-server communication, freeing up time to focus on higher-impact tasks. In this guide, we'll implement passwordless authentication between two EC2 instances—one of the countless small but powerful skills on the path to DevOps mastery.

---

### Prerequisites

Before diving in, make sure you have:

* Two or more AWS EC2 instances to work with
    
* Basic SSH and terminal command skills
    
* Sudo access on each instance
    

This task may seem straightforward, but it’s a building block for more complex DevOps skills. Embrace each step, knowing that small tasks like these compound to make a real difference over time.

---

### Steps to Implement Passwordless Authentication

#### Step 1: Launch and Connect to EC2 Instances

Start by creating two EC2 instances on AWS. Each server you work with will help build your familiarity with cloud infrastructure and how different environments communicate. Connect to each instance via SSH:

```bash
ssh -i "your-key.pem" ubuntu@<private_ip_of_your_instance>
```

#### Step 2: Update and Upgrade Both Servers

In DevOps, consistency matters. Ensuring your servers are up-to-date prevents compatibility issues and keeps the environment clean and predictable. Run the following on each instance:

```bash
sudo apt update && sudo apt upgrade
```

#### Step 3: Generate SSH Keys on the Target Server

Log into the **target server**—the server you’ll connect to without a password. By generating a unique SSH key, you’re setting up a secure, cryptographic handshake between servers. Run:

```bash
ssh-keygen
```

This will create a public key (`id_`[`ed25519.pub`](http://ed25519.pub)) and a private key (`id_ed25519`) in the `~/.ssh` directory. Think of these keys as your servers’ secret handshake.

#### Step 4: Copy the Public Key from the Target Server

Copy the public key to be added to the source server. This key will be your link to passwordless access:

```bash
cat ~/.ssh/id_ed25519.pub
```

#### Step 5: Add the Public Key to the Source Server’s `authorized_keys`

Now, log in to the **source server**. Open the `authorized_keys` file, which lists all approved public keys, giving you seamless access between the servers:

```bash
vim ~/.ssh/authorized_keys
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730968973530/ef72b37c-ea5b-45ca-9481-6b97b23a6b04.png align="center")

#### Step 6: Append the Public Key to `authorized_keys`

Paste the copied public key from the target server at the end of this file. Save and close the file. You’re now one step closer to establishing a secure, passwordless connection.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730969016313/07643ec3-788a-4d7d-8e77-284e49f75105.png align="center")

#### Step 7: Test the Passwordless Connection

Testing is essential in DevOps. Run this command on the **source server** to try connecting to the **target server** without a password:

```bash
ssh <private_ip_of_target_server>
```

If everything is configured correctly, you’ll be logged in without a password prompt! This confirmation might feel small, but it’s a powerful step forward in your DevOps journey.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730969050462/da6ab251-ddf0-4ba2-bb2c-86fe463e324b.png align="center")

#### Step 8: Verify the Setup

To solidify your understanding, create a directory on the target server and confirm it’s visible from the source server.

1. On the target server:
    
    ```bash
    mkdir amitabh
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730969113543/f7637ad6-520f-4c21-893f-e7d220c04c8b.png align="center")
    
2. On the source server, SSH into the target server and list the contents:
    
    ```bash
    ls
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730969235509/ebbf5b62-d989-4476-a1f0-c099591918e4.png align="center")
    
3. Seeing `amitabh` confirms your setup is working perfectly.
    

---

### Final Thoughts: DevOps is About Mindset and Skills

Passwordless authentication is a single skill, but it’s a cornerstone of the DevOps mindset. By automating and securing connections between servers, you’re learning the power of simplicity and efficiency. Each small step, task, and problem solved builds your confidence and capability.

Keep pushing forward, knowing that mastering these fundamentals brings you closer to a full grasp of DevOps. Embrace each moment, and remember: every command executed, every connection made, and every problem solved is part of your journey to becoming a DevOps professional.
