How to set up a server with Hetzner
Tags: laravel, php, webdev, hetzner
Published: 2024-03-13 12:49:00

In this guide we'll be showing you how to navigate the Hetzner Cloud control panel so you can create your own server and integrate it into ServerAuth for easier server management.

## Getting started

For the purpose of this guide, we'll assume you already have accounts with Hetzner and ServerAuth. If not, do that now before proceeding.

* [Hetzner Signup](https://accounts.hetzner.com/signUp)
* [ServerAuth Signup](https://app.serverauth.com/register)

If you prefer a more automated approach then skip ahead to the [Easier alternative setup](#an-easier-alternative-setup). With this method we create the server on your behalf using the Hetzner API.

## Navigating Hetzner

When you first login to hetzner you want to ensure you are logging in to the Cloud section of Hetzner. In doing so, you should see a screen similar to this.

![Screenshot showing Hetzner control panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k59syqi7mk0x3y5a1agq.png)

To help get you started, Hetzner create a Default project for you. A project is essentially a wrapper for servers and their configurations. This allows you to group related servers together and isolate them from different projects in your account. 

For this guide, we'll use the Default project Hetzner create for you, but if you wish create a new project before proceeding. 

## Creating your server

To create your first server, click the "+ Create Server" link within the project box.

![Screenshot showing Hetzner create server link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6btoa3jtvm3lplcl4a4.png)

This will take you to the page to create your server with Hetzner. The first step of which is to select which location you wish to use. 

![Screenshot showing Hetzner select location options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5kzkgtijwgk18n64imf.png)

For this guide, we've selected Ashburn, VA which is US east. Next up, we have to select the operating system and version we want Hetzner to install on the server on creation. For maximum compatibility with ServerAuth features, we've selected Ubuntu 22.04.

![Screenshot showing Hetzner select os options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fx3qyy6tvsh4tkmpao0.png)

You will then be asked to select the CPU type for your server. For the purposes of this guide, we've opted for a shared CPU and selected the CPX11 which gives us 2vCPUs, 2GB RAM and 20TB of traffic.

![Screenshot showing Hetzner select cpu type options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcjs0eivavf6rvx5vgn8.png)

In the next section you can customize some basic networking settings. As standard all Hetzner instances include a free IPv6 addresses, however you'll likely want to select an IPv4 address. To use these you'll be charged an extra fee of €0.00096/hour, or approx €0.70/month (prices correct at the time of publication).

The next option is to set up SSH keys for your root user. Grab your SSH key from your computer, if you're on Mac or Linux you can run the following command.

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

This should output your SSH key into termainal for you to copy and paste. If you haven't yet got a SSH key on your computer, you can follow the first part of our guide, [How to Set up SSH Keys](https://serverauth.com/posts/how-to-set-up-ssh-keys).

![Screenshot showing Hetzner select add ssh key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kc73qjrlarfu0599jqo.png)

Once, you have your SSH key copied to clipboard, click the add SSH key button and paste your key into the modal window that appears.

For this guide, we are skipping the rest of the config. Depending on your use case you may need to add more hard drives to the server via the Volumes section or enable backups. 

**Note** We'd recommend not using the firewall within Hetzner control panel if you wish to use the Firewall management within ServerAuth.

Lastly, Hetzner will generate a name for your server based upon some of the options selected however, you can amend this and give your server a more recognisable name so you know what the purpose of the server is. On the right of the screen, you should also see something similar to this depending on what options you have selected.

![Screenshot showing Hetzner checkout summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tor2mqwnijn325tsgvcs.png)

Once you're happy, click Create & Buy now. Hetzner will start creating your server and you will be redirected to the server listing page.

![Screenshot showing Hetzner server list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kt8w07m9j8g74aprhx4u.png)

You can hover over the icon next to the server name to find out the status. When it's green like this screenshot, it should mean your server is up and running. Click the IP address to copy it to your clipboard ready for ServerAuth integration.

## Integrating ServerAuth

When you first login or create your account with ServerAuth, you will be presented with a screen like this.

![Screenshot showing ServerAuth server list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ys5eqzut33ubij8kxvrr.png)

Click the "Add a Server" button to get started with integration to ServerAuth. You'll be presented with an option to select a server provider.

![Screenshot showing ServerAuth select server provider screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4lbd6a9092hye9n7tp0.png)

Select the "Create custom server" option, this will take you into the 3 step process for integrating ServerAuth into your server.

Step 1 asks you to select the operating system of your server, we selected Ubuntu 22.04 during server creation so select that again here. Then enter a recognisable name for your server so you can identify it within ServerAuth. For the purpose of this guide, you can leave Server Users blank and also ignore tags. Click next, when you're done.

![Screenshot showing ServerAuth add server step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awx2p1a2meavt9sd3vnm.png)

Step 2 asks you for some more information regarding the server. Grab the server IP from Hetzner if you don't already have it saved to your clipboard, and then paste it into the Server IP box.
You can leave SSH Port as 22. For the SSH Username, enter "root" and click next.

![Screenshot showing ServerAuth add server step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdkd7ff4u2299l49ruk3.png)

Step 3 is where we start to connect to your server. When creating the server in Hetzner, we added our SSH Key rather than use a password, this is always the preferred option over using SSH passwords.

![Screenshot showing ServerAuth add server step 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxp9w4zdfn0qeh9memen.png)

Select "SSH Connection" option and you will be presented with your ServerAuth teams SSH key. This is used by our system to authenticate with your server so we can configure it. Copy your teams SSH key and open up your terminal.

SSH into your root user on your newly created server with the following command, remember to switch out the IP address for your IP.

```bash
ssh root@[your-server-ip]
```

Once you are connected, open up the `authorized_keys` file for your root user, this can be found at `~/.ssh/authorized_keys`.

For this guide, I'm using nano to edit the file but use whatever editor you are most comfortable with.

```bash
nano ~/.ssh/authorized_keys
```
You will see a SSH key already in the file from Hetzner setup. Move the cursor to a new line and paste in your ServerAuth team SSH key, and save the file. 

Head back to your ServerAuth window, and check the box to confirm you have added the SSH key to your user and click Test Connection. The button will change to show it is currently testing the connection to your server and once complete, the options should change at the bottom allowing you to setup the server.

![Screenshot showing ServerAuth test connection results](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gkrdy8te5ol2mjq8csg8.png)

Click the Setup Server button to start the setup process. You will be redirected to a processing screen, showing you the steps to setup your server and highlighting which step the process is currently on.

![Screenshot showing ServerAuth building server screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjqj3gpy9r5h6hmtuv2f.png)

Once setup is successfully completed, you will be redirected the server details screen! Setup is now all complete and you can begin to use ServerAuth to manage your server.

![Screenshot showing ServerAuth server details screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1x0eu6wjrqkmk5it16h.png)

## An easier alternative setup

There is also an easier, alternative way to setup your server with Hetzner and integrate it into ServerAuth!

First head to your Hetzner account and click into a project. Hover over the left menu and click into "Security" at the bottom of the menu.

![Screenshot showing Hetzner Security menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oc4c7i4a4aljvri7e1xo.png)

The first screen will show you any SSH keys you have saved. Next click the sub menu to load the API Tokens page.

![Screenshot showing Hetzner API Tokens page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ghon5txfx6hkr2hhqms.png)

Click the button to generate an API token. A modal will appear, give the API token name so you know what it's used for and grant it read and write access, then click Generate API Tokens.

![Screenshot showing Hetzner API token generation modal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20nh8zj13dgq496ti1cc.png)

Click to show your API token and make sure you copy it. Head back to ServerAuth and in the top menu, click the Team link and then the "Server Providers" link in the side menu. You will be presented with a box to create a new server provider.

![Screenshot showing ServerAuth new provider box](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t3f0h023w1w0xyi03vzx.png)

Give the provider a name, if you have multiple Hetzner accounts this could be the name or email on the Hetzner account or some other identifier. Select Hetzner from the provider dropdown. A box will appear to add your API Token. Paste it in then hit save.

Click the Servers link in the top menu and click to Add a Server. You will notice that this page looks slightly different from before as you will now have Hetzner as a server provider option.

![Screenshot showing ServerAuth select provider page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg6i0kuqy4gsw88uf3j2.png)

Click the Hetzner provider and you will be taken to a new page to enter a recognisable name for your server and then to select which region you wish to create your server in. These will match the options available in the first step when creating the server within Hetzners control panel.

![Screenshot showing ServerAuth create server step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5h181lbdia95nkdup9f4.png)

Once you select your region, there will be a short delay as we use your API token to retrieve the available server types and prices from Hetzners API. 

![Screenshot showing ServerAuth select type step](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ihmjcvvd9fngxyny9bu.png)

You can change the region and the list of available server types will update to reflect availability and pricing. For this guide, we selected to create another CPX11 server. You can also ignore the remaining options. Click Create Server to start the process!

You will be presented with a similar processing screen as before, however wording will be slightly different to reflect the different processes now occurring.

![Screenshot showing ServerAuth server building screen via server provider](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odvz2wby54cjtve5fwa9.png)

In the background, our systems are now creating the server in your Hetzner account via the API and your API token. Once the server has been created, our server management setup will begin and our system will start to configure everything it needs to manage your server.

Once complete, you will be redirected to the familiar server details page.

![Screenshot showing ServerAuth server details page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0q8so07eo1uanf85cdxs.png)

Whichever method of integration you chose, setup is now complete! You can use the left menu to access the various options available and start managing your server like a pro!

Check out our [help site](https://serverauth.com/docs/getting-started) for more information or assistance on using parts of the system. Alternatively, if you can't find the answer you're looking for, within the ServerAuth platform, you should see the "Need Help?" link in the header. Use this to get in touch with us and we'll do our best to answer any questions you have!