How to Add an SSH Key to Your Hetzner Server
If you’re looking to add an SSH key to your Hetzner server, you’ve come to the right place! SSH keys are a secure way to access your server without having to rely on a password. In this guide, we’ll walk you through the process of adding an SSH key to your Hetzner server step by step.
Before we get started, make sure you have an SSH key generated on your local machine. If you don’t have an SSH key yet, you can easily generate one using the following command:
$ ssh-keygen -t rsa -b 4096
This command will generate an RSA SSH key with a length of 4096 bits. Once you have your SSH key generated, you can follow the steps below to add it to your Hetzner server.
Step 1: Copy Your SSH Key
The first step is to copy your SSH key to the clipboard. You can do this by running the following command in your terminal:
$ pbcopy < ~/.ssh/id_rsa.pub
This command will copy your SSH key to the clipboard so that you can easily paste it into your Hetzner server.
Step 2: Log in to Your Hetzner Server
Next, you'll need to log in to your Hetzner server using SSH. You can do this by running the following command in your terminal:
$ ssh root@your_server_ip_address
Replace your_server_ip_address
with the IP address of your Hetzner server. Enter your server's root password when prompted.
Step 3: Add Your SSH Key to the Authorized Keys File
Once you're logged in to your server, you'll need to add your SSH key to the authorized_keys
file. You can do this by running the following commands:
$ mkdir -p ~/.ssh
$ echo "PASTE_YOUR_SSH_KEY_HERE" >> ~/.ssh/authorized_keys
Replace PASTE_YOUR_SSH_KEY_HERE
with the SSH key that you copied to your clipboard in Step 1. Make sure to paste the entire key, including the ssh-rsa
prefix and your email address.
Step 4: Test Your SSH Key
Once you've added your SSH key to the authorized keys file, you can test it by logging out of your server and attempting to log back in using the SSH key. You should be able to log in without entering a password.
Congratulations! You've successfully added an SSH key to your Hetzner server. Using SSH keys is a more secure and convenient way to access your server, so make sure to keep your private key safe and secure.
That's it for this guide on how to add an SSH key to your Hetzner server. If you have any questions or run into any issues, feel free to reach out to Hetzner's support team for assistance. Happy server managing!