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

# How to Generate an SSH Key and Add It to a Server

> How to generate an SSH key and add it to a server: run ssh-keygen -t ed25519, copy the .pub key with ssh-copy-id or into ~/.ssh/authorized_keys, then log in.

To generate an SSH key, run `ssh-keygen -t ed25519 -C "alex@laptop"` on your own computer and set a passphrase. Then add the public key to the server with `ssh-copy-id -i ~/.ssh/id_ed25519.pub alex@203.0.113.10` (macOS and Linux), or append the contents of `id_ed25519.pub` to `~/.ssh/authorized_keys` on the server. Your next `ssh alex@203.0.113.10` logs in with the key instead of the server password.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Windows 10 / 11, macOS, Linux (client); any Linux server running OpenSSH | Password login that still works, or access to the VPS Control Panel |

## Before you start

* You need to be able to log in to the server once, with a password, to install the key. Or add the key in the [VPS Control Panel](https://help.freakhosting.com/portals/vps-panel/how-to-manage-ssh-keys.md) before you [rebuild the VPS](https://help.freakhosting.com/portals/vps-panel/how-to-rebuild-and-reinstall-your-vps.md).
* An SSH key comes in two files. The **private key** (`id_ed25519`) stays on your computer and is never shared. The **public key** (`id_ed25519.pub`) goes on every server you want to log in to.

## Which key type should I use?

Use **Ed25519**. It is short, fast and supported by every current OpenSSH server. Use RSA with 4096 bits only for old systems that don't accept Ed25519.

| Key type | Command | When to use |
| - | - | - |
| Ed25519 | `ssh-keygen -t ed25519` | Default choice for all current servers |
| RSA 4096 | `ssh-keygen -t rsa -b 4096` | Old devices or software without Ed25519 support |

## How to generate an SSH key

The command is the same in PowerShell on Windows and in Terminal on macOS and Linux.

**1. Run ssh-keygen**

```bash theme={null}
ssh-keygen -t ed25519 -C "alex@laptop"
```

The `-C` text is a label that helps you recognise the key later.

**2. Accept the file location**

Press **Enter** to save to the default location: `~/.ssh/id_ed25519` on macOS and Linux, `C:\Users\<you>\.ssh\id_ed25519` on Windows.

**3. Set a passphrase**

Type a passphrase twice. It encrypts the private key, so a stolen laptop doesn't mean a stolen server.

**4. Check the result**

```text theme={null}
Your identification has been saved in /home/alex/.ssh/id_ed25519
Your public key has been saved in /home/alex/.ssh/id_ed25519.pub
```

## How to add the public key to your server

> [tab] macOS / Linux
>
> `ssh-copy-id` logs in with your password once and appends the key with the right permissions:
>
> ```bash theme={null}
> ssh-copy-id -i ~/.ssh/id_ed25519.pub alex@203.0.113.10
> ```
>
> For a non-standard SSH port, add `-p 2222`.

> [tab] Windows (PowerShell)
>
> Windows has no `ssh-copy-id`. This one-liner does the same job. It asks for your server password once:
>
> ```powershell theme={null}
> type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh alex@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
> ```

> [tab] Manually on the server
>
> Show the public key on your computer (`cat ~/.ssh/id_ed25519.pub`, or `type $env:USERPROFILE\.ssh\id_ed25519.pub` on Windows) and copy the single line. Log in to the server and run:
>
> ```bash theme={null}
> mkdir -p ~/.ssh
> chmod 700 ~/.ssh
> nano ~/.ssh/authorized_keys
> ```
>
> Paste the line on its own line, save with **Ctrl+O**, exit with **Ctrl+X**, then:
>
> ```bash theme={null}
> chmod 600 ~/.ssh/authorized_keys
> ```

The key goes into the home folder of the user you log in as: `/root/.ssh/authorized_keys` for root, `/home/alex/.ssh/authorized_keys` for `alex`. If you created the folder as root for another user, give it back to that user with `sudo chown -R alex:alex /home/alex/.ssh`.

## How to check it worked

Log in again from your computer:

```bash theme={null}
ssh alex@203.0.113.10
```

You are asked for the **key passphrase** (`Enter passphrase for key ...`), not the server password. To prove the key alone works, force SSH to skip passwords:

```bash theme={null}
ssh -o PasswordAuthentication=no alex@203.0.113.10
```

If that logs you in, you can safely [disable password logins](https://help.freakhosting.com/portals/other/how-to-disable-password-login-for-ssh.md).

> [!WARNING]
>
> Keep a backup of your private key. If you lose it after turning off password logins, you can only get back in through the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md) or [rescue mode](https://help.freakhosting.com/portals/vps-panel/how-to-use-rescue-mode.md) on a VPS, or by [opening a ticket](https://freakhosting.com/clientarea/submitticket.php) for a dedicated server.

## Frequently asked questions

### Can I use the same key for several servers?

Yes. Add the same public key to each server. If one computer is lost, remove that key line from `authorized_keys` on every server.

### How do I avoid typing the passphrase every time?

Use the SSH agent. On macOS and Linux, run `ssh-add ~/.ssh/id_ed25519` once per login session. You can also add `AddKeysToAgent yes` to your [SSH config file](https://help.freakhosting.com/portals/other/how-to-use-ssh-config-file-shortcuts.md).

### Why does the server still ask for a password?

The key isn't in the right `authorized_keys` file, the line is broken, or the permissions are too open. SSH refuses keys when `~/.ssh` or `authorized_keys` is writable by other users. See [permission denied (publickey)](https://help.freakhosting.com/portals/other/how-to-fix-ssh-permission-denied-publickey.md).

### How do I use this key with PuTTY or WinSCP?

PuTTY needs a `.ppk` copy. Convert it in PuTTYgen with **Conversions > Import key**. See [How to use PuTTY](https://help.freakhosting.com/portals/other/how-to-use-putty-to-connect-to-your-server.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Disable password login](https://help.freakhosting.com/portals/other/how-to-disable-password-login-for-ssh.md)
>
> Allow SSH keys only.

> [card] [SSH config shortcuts](https://help.freakhosting.com/portals/other/how-to-use-ssh-config-file-shortcuts.md)
>
> Pick the right key per server automatically.

> [card] [Use PuTTY](https://help.freakhosting.com/portals/other/how-to-use-putty-to-connect-to-your-server.md)
>
> Keys in PuTTY's .ppk format.

> [card] [Manage SSH keys in the VPS panel](https://help.freakhosting.com/portals/vps-panel/how-to-manage-ssh-keys.md)
>
> Add keys before a rebuild.

***

> [!NOTE]
>
> **Checked against the official [OpenSSH ssh-keygen manual](https://man.openbsd.org/ssh-keygen) and [Microsoft Learn: OpenSSH key management](https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement)** on 4 November 2026; `ssh-keygen`, `ssh-copy-id` and key login tested with OpenSSH 9.6 on Ubuntu 24.04 LTS. The PowerShell one-liner was not tested on Windows.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


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