# Step-by-Step Guide to Linking an SSH Key with Your GitHub Repositories

### 1\. **Generate a New SSH Key**

Run the following command to generate a new SSH key specifically for GitHub:

```bash
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_github
```

Explanation:

* `-t ed25519`: Specifies the key type.
    
* `-C "`[`your_email@example.com`](mailto:your_email@example.com)`"`: Adds a comment to the key (typically your email).
    
* `-f ~/.ssh/id_github`: Specifies the file name for the new key.
    

During the process, you’ll be prompted to:

1. Confirm the file location (press `Enter` to accept the default).
    
2. Enter a passphrase (optional, but recommended for added security).
    

### 2\. **Verify the Key Files**

Once the SSH key is created, confirm the existence of the key files using:

```plaintext
ls -l ~/.ssh/id_github*
```

You should see:

* **~/.ssh/id\_github**: The private key (keep this secure and never share it).
    
* **~/.ssh/id\_github.pub**: The public key (this will be added to GitHub).
    

### 3\. **Add the Key to Your SSH Agent**

Add the private key to your SSH agent to manage it easily:

1. Start the SSH agent:
    
    ```bash
    eval "$(ssh-agent -s)"
    ```
    
2. Add the key to the agent:
    
    ```bash
    ssh-add ~/.ssh/id_github
    ```
    

### 4\. Copy the Public Key to Your Clipboard

To add the key to GitHub, first copy the public key:

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

### 5\. Add the SSH Key to Your GitHub Account

1. Log in to your GitHub account.
    
2. Navigate to **Settings &gt; SSH and GPG keys**.
    
3. Click **New SSH key**.
    
4. Paste your public key into the provided field.
    
5. Add a title to identify this key (e.g., "Server").
    
6. Click **Add SSH key**.
    

### 6\. Test the SSH Connection

Verify the connection to GitHub using:

```bash
ssh -i ~/.ssh/id_github -T git@github.com
```

If successful, you should see a message like:

```plaintext
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
```

### 7\. Using the SSH Key for Repository Management

#### Clone a Repository

Use the SSH URL to clone a repository:

When pushing changes, Git will automatically use the SSH key for authentication:

```bash
git clone git@github.com:<username>/<repository>.git
```

#### Push Changes

```bash
git push origin main
```

## Conclusion

By setting up an SSH key with GitHub, you’ve simplified your authentication process and secured your repository management workflow. No more password prompts—just smooth, secure Git operations!
