> ## Content Index
> Fetch the complete content index at: https://catalins.tech/llms.txt
> Use this file to discover other available public pages before exploring further.

# Add SSH Keys to a Hetzner VPS
- URL: https://catalins.tech/add-ssh-keys-to-a-hetzner-vps/
- Published: 2026-05-30T10:12:24.000Z
- Updated: 2026-05-30T10:12:24.000Z
- Author: Catalin Pit
- Tags: Self-host, Hetzner

## Generate an SSH Key

Generate an SSH key using the Ed25519 algorithm:

```bash
ssh-keygen -t ed25519 -C "<your-email-address>"
```

After running the command, you’ll be prompted to choose where to save the key.

Using the default file `id_ed25519` will overwrite the previous content, and you may run into trouble with SSH authentication for other clients.

To avoid that, I save my keys in different files:

```ts
Enter file in which to save the key (/Users/<your-username>/.ssh/id_ed25519): /Users/<your-username>/.ssh/vps_selfhosting
```

After specifying the file in which to save the key, you need to enter a passphrase. Although you can continue without one, I recommend that you add one.

Once you add it, the SSH setup is complete.

For more information about setting up SSH keys, check out [this article from GitHub](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).

### Adding SSH Keys to a Hetzner VPS

You now need to add the public key to your Hetzner VPS. You can copy it as follows:

```bash
cat .ssh/vps_selfhosting.pub | pbcopy
```

Return to the VPS configuration page and paste the key.

![](https://catalins.tech/content/images/2025/05/hetzner-vps-ssh-key.webp)

> Important: Don't blindly copy my choices. Use the options that fit your needs and requirements.

## SSH Into VPS

You can now SSH into your VPS as follows:

```bash
ssh root@<your-vps-ip> -i ~/.ssh/vps_selfhosting
```

However, passing the SSH key every time you want to access your VPS is annoying. Add the key to the SSH agent:

```
ssh-add ~/.ssh/vps_selfhosting
```

Now you can run `ssh root@<your-vps-ip>`.

## Create an SSH Host Alias

Even better, create a host alias so you don’t need to type the full command every time.

Open your SSH config file:

```
vi ~/.ssh/config
```

And add the following:

```
Host <alias> (e.g. myvps)
  HostName <vps-ip>
  User <username>
  IdentityFile ~/.ssh/<key-name>
  IdentitiesOnly yes
  ServerAliveInterval 30
  ServerAliveCountMax 3
```

Now you can log into your VPS with `ssh myvps`.