A Linux server on Hetzner

In this tutorial, you will learn how to create a Linux server on Hetzner.

Task 1: Create an Hetzner account

As a new Hetzner, you are eligible for a $20 discount. You can create an account through the promotional link here: https://hetzner.cloud/?ref=TOmrsMdmfCLf. Follow the prompts to create a new account with your email, verify identity, and fill in profile information. Note that you might be asked for your ID information and credit card number, which is a normal process to get an account in Hetzner.

Task 2: Set up SSH key (Optional)

To set up public-key authentication, follow the instructions below.

Open Windows Powershell, and run the following command to generate SSH keypair.

ssh-keygen -t rsa -b 4096

Where: When asked which file to save the key, you can type the name. Next, you can enter a passphrase to encrypt the private key, but you will need to enter this passphrase every time when you log into the Linux server. If you don't want it, you can press Enter, so it will have no passphrase.
    PS C:\Users\xtao> ssh-keygen -t rsa -b 4096
    Generating public/private rsa key pair.
    Enter file in which to save the key (C:\Users\xtao/.ssh/id_rsa): test
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in test
    Your public key has been saved in test.pub
    The key fingerprint is:
    SHA256:zapwdxFru4dE+o5uaqUqpRTjskjafHjWWly1xwDLcJ4 ad\xtao@GEOGLT075
    The key's randomart image is:
    +---[RSA 4096]----+
    |      . o        |
    |       = +       |
    |        E +      |
    |  o      +.*     |
    | . o    SoB o    |
    |..o .. .oo.+     |
    |+* +..+oooo.     |
    |+ * +++o.oo..    |
    |   =o+o+o.o.     |
    +----[SHA256]-----+
        
Copy your SSH public key, which will be used in Task 3. If you have PuTTY installed, you can also use the PuTTY Key Generator to generate keypair.

Task 3: Create a server

In the Hetzer, create a new server by following these steps:

  1. First, create a new project, and then create new resource > Servers

    Create a server on Hetzner
  2. Select Add server

    Add a server on Hetzner
  3. Set your server type. A suggested one is Regular Performance. Choose the region to be Hillsboro, OR (us-west), and choose Ubuntu Server 22.04 as the Image. Your settings may look like the figure below.

    Create a server on Hetzner

    If you have SSH key, add SSH key. Otherwise, you will receive the root password via email. Finally, give your server a name, and click Create & Buy now button.

  4. You have now created an Hetzner server! In the next section, you will access the new machine.

Task 4: Connect to the Server

To connect to an Hetzner server from Windows or Mac, you can use SSH. Here are the steps to connect to a Hetzner server from both Windows and Mac.
  1. Open the Command Prompt or PowerShell on your Windows computer or Terminal on Mac.
  2. Type the connection string like the following format:
    ssh -i ~/.ssh/id_rsa.pem user@135.235.160.38
    An example for connection is as follows:
    ssh -i osrmOpen root@135.235.160.38
    Note: if you do not have SSH key setup, use the following format:
    ssh root@135.235.160.38
  3. Hit enter key to connect to the server.
You should now be connected to your Hetzner server using SSH.

Task 5: Opening the HTTP and HTTPS Port

In order to make websites available to the outside world, we need to allow Internet traffic to find it. Computers communicate to each other through “ports,” or specific addresses that a piece of software uses to either 1) listen for data or 2) send out data. For HTTP, the protocol used for web servers, this is traditionally port number 80. By default, ports are closed for security reasons – a port should not be open unless it has a purpose. Your next step is to tell Hetzner to open the port so that your server can communicate with the outside world over HTTP.

To open port 80 and 443 in an Hetzner, follow these steps:

  1. Go to Firewalls on the left menu bar

    Go to firewalls on left menu bar
  2. Select Create Firewall

    Select create firewall
  3. Create your Firewall

    Create firewall setting
  4. Click on the "Add rule" button to add a new inbound security rule.
  5. In the "Add description" dialog box, modify destination port ranges. Set this to "80", which is the default for HTTP traffic.
  6. Similarly, add another rule for port 443.
  7. Finally, give your firewall a name.
  8. Go to your server details, and click Firewall tab, and then Apply Firewall button
  9. Choose your defined firewall, and then click Apply 1 Firewall.

Next Step

I hope this tutorial helped you create a Linux server on Hetzner. Please continue to set up web apps to provide functions.