labnotes

Controlling Hetzner with CLI

Simple wrapper scripts

tags
hetzner
cloud
cli

Install the cli

1
brew install hcloud

Go into your https://console.hetzner.cloud/ and get an API key.

Creating a server

Then create a context for your script to use, for example:

1
  hcloud context create willschenk

Then we can see if its in use:

1
  hcloud context list
1
2
ACTIVE   NAME
,*        willschenk

List servers:

1
  hcloud server list
1
ID   NAME   STATUS   IPV4   IPV6   PRIVATE NET   DATACENTER   AGE

Nothing there! Lets create one. First we need to select an image, and we can see if they have any debian-12 images:

1
hcloud image list | grep debian-12
1
2
114690387   system   debian-12            Debian 12            x86            -            5 GB        Tue Jun 13 02:00:02 EDT 2023   -
114690389   system   debian-12            Debian 12            arm            -            5 GB        Tue Jun 13 02:00:03 EDT 2023   -

Looks good. We can also list out server types using

1
  hcloud server-type list

And we will chose cx11 which has 1 core, 2GB of ram, and 20GB of storage.

Finally we'll want to add a ssh key to the server so we can log in. If you haven't done so already, configure yours into the cloud console.

You can list them out using

1
  hcloud ssh-key list
1
2
ID         NAME                FINGERPRINT                                       AGE
11424818   wschenk@gmail.com   b0:80:12:6e:1e:8e:ee:3f:4f:03:56:2c:1e:4d:4d:29   14d

So lets do it:

1
  hcloud server create --name apple --type cx11 --image debian-12 --ssh-key 11424818

Lets run this and we get:

1
2
3
4
5
6
5.8s [===================================] 100.00%
Waiting for server 33932970 to have started
 ... done                                                                                                                                                                             Server 33932970 created
IPv4: 65.108.63.49
IPv6: 2a01:4f9:c012:6903::1
IPv6 Network: 2a01:4f9:c012:6903::/64

And, in this case, you should be able to log on to the machine using

1
ssh root@65.108.63.49

Deleting a server

We can remove the server that we created using

1
hcloud server delete 33932970
Server 33932970 deleted

Previously

labnotes

Playing with SSHKit

Deployment testing

tags
sshkit
ruby

Next

labnotes

Using the cloudflare API

setting A records ez

tags
cloudflare
cloud
cli