Skip to main content

Command Palette

Search for a command to run...

My Journey to Self-Hosting: Part 1 - VPS and SSH Key

Updated
4 min read
My Journey to Self-Hosting: 
Part 1 - VPS and SSH Key
N
I'm a Full-Stack Web Developer and enthusiastic nature photographer from Switzerland.

This article is also available in German (Deutsch).

If you develop several small web apps and hobby projects, you’ll quickly run into a financial problem: if you pay for separate hosting or a PaaS (Platform as a Service) like Heroku or Render for each project, the monthly fixed costs add up very quickly.

That’s why I want to have my own VPS for my small projects, one that gives me full control and lets me run as many apps as I want without additional costs (as long as the RAM and CPU are sufficient 😉).

VPS Lite

To get started, I’ve decided to go with VPS Lite from the Swiss provider Infomaniak. VPS Lite stands for “Virtual Private Server Lite” and is simply a cost-effective, stripped-down version of a virtual private server. Another reason I chose this provider is that their servers are 100% hosted in their own Swiss data centers.

After completing the order, all I have to do is choose an operating system (I went with Ubuntu) and wait a short while for the installation to finish.

SSH Key

To connect to my server, I need an SSH key (a secure key pair). I generate this using the Terminal (I'm using a Mac):

ssh-keygen -t ed25519 -C "vps" -f ~/.ssh/vps

ssh-keygen: stands for “SSH Key Generator” and launches the program to generate the keys

-t ed25519: specifies the encryption algorithm

-C “vps”: adds a comment so I know later what the keys are for

-f ~/.ssh/vps: specifies the folder and filename where the keys will be saved

Two files are generated:

  • vps (the private key): this is like a house key, it stays on my own computer, and no one else is ever allowed to see this key

  • vps.pub (the public key): this is the lock that is stored on the VPS

Every time I log in, the server uses this lock to verify that my computer has the matching private key.

The Infomaniak advantage: Normally, you would have to upload this key to the server manually via the command line. However, Infomaniak makes our lives easier, I can simply copy the contents of the vps.pub file and paste it directly into the Infomaniak web interface. The system then installs the key automatically for me.

Establishing a connection

In the terminal, I can now establish the connection as follows:

ssh -i [key_path] [user]@[server_IP]

In practice, this looks like this (example):

ssh -i ~/.ssh/vps ubuntu@123.45.67.89

ssh: starts the protocol for a secure connection

-i ~/.ssh/vps: the -i stands for “Identity File”, here you specify the path to the private SSH key on your local computer

ubuntu: the default username that Infomaniak has set up for the selected operating system

123.45.67.89: the IP address of the VPS Lite (you can find this in the Infomaniak dashboard under “Startup Procedure”)

Tip for the lazy 😉

To avoid having to type this long command every time you want to connect to the server, you can create shortcuts in a local file.

Use this command to create the file:

touch ~/.ssh/config

Then add the following to the file:

Host vps
    HostName 123.45.67.89
    User ubuntu
    IdentityFile ~/.ssh/vps
    IdentitiesOnly yes

When connecting to a server, SSH tries all the keys in the ~/.ssh folder or loaded in the background one after another until one works. IdentitiesOnly yes prevents this by sending the correct key immediately.

Now I can easily connect to my VPS in the terminal using the command ssh vps.

What's next?

The first connection is up! 🎉 The server is running, but it's still completely “bare.” In the next part, I'll secure the server and set up a firewall.

My Journey to Self-Hosting

Part 1 of 2

This blog series chronicles my journey to self-hosting. I’ll show you how I set up, secure, and configure an affordable Swiss VPS Lite so that I can run as many apps and websites as I want on it simultaneously.

Up next

My Journey to Self-Hosting: Part 2 - Securing the Server

In the last article, I se tup Infomaniak's VPS Lite server and logged in via SSH. The server is up and running, but a brand-new sever is like an open front door, anyone can try to enter. In this secon

More from this blog

N

Nathalie's Notebook

2 posts

Welcome to my learning notebook! This is where I document my personal insights, step-by-step guides, and clear explanations. My goal is to share knowledge structurally and break down complex topics into simple terms.