Vps
liongrass / May 2023 (1656 Words, 10 Minutes)
Prepare a virtual private server (VPS)
This guide is written for setting up a VPS with Lunanode, a solid hosting provider based in Toronto, Ontario. We recommend them partly because weâve been running a Lightning node there for several years, and partly because they accept Lightning payments directly into their own node. For the purpose of running a Lightning Node, you may choose any other provider, given they can give you full ssh access to a Linux instance.
Other popular providers that accept Lightning are Namecheap, Cherryservers, Hostinger or Bitlaunch (reselling Digital Ocean).
Create an account
First, you will need to create an account. Youâll be asked for an email address, password and a country. They will later require a phone number for verification, so if you are using a service like SMS4SATS, plan ahead!
Your security is important: If you signed up with a phone number that isnât yours, make sure this phone number isnât automatically added to your account for recovery purposes. Under Account in the top panel, you can opt into two-factor authentication. I recommend âtime-based one-time passwordâ.
Deposit funds into your account
We will have to deposit some funds into our account. Under Billing in the top panel we can make a lump-sum payment into our account. Try adding US$5 via BTCPay (Lightning) if you already have a mobile Lightning wallet.
SSH access
In this step, we are going to get ready to access our server from our personal computer via SSH. To do that, we are going to first create an SSH key. We recommend you creating a new SSH key, in case you will later need to revoke it or exchange it.
Create an SSH key on your personal machine
In Mac OS X, Windows or Linux we are going to open a terminal for the first time and execute the following.
ssh-keygen
Windows:
- Open Windows Powershell
- type
ssh-keygen
- ** IMPORTANT ** Do not enter a key name
- Follow the prompts and a new âid_rsa.pubâ (public key) and âid_rsaâ (private key) files will be generated at
C:\Users\userName\.ssh\id_rsa.pub
Linux, Mac OS X:
We are typically asked for a name for this key, for example nodekey_rsa
. You may optionally choose a passphrase for this key, meaning you will have to enter this passphrase every time you log into your machine. Your public key will be called newkey_rsa.pub
and it will be saved in the following location:
Linux: ~/.ssh/newkey_rsa.pub
Mac OS: /Users/MYUSERNAME/.ssh/newkey_rsa.pub
In our Lunanode account, under Account, we can find the option SSH Keys. We can add our SSH key there. Give it a name (ideally the name of the computer that belongs to this key), paste your public key into the appropriate field and add it.
You can add multiple SSH keys here, for example if you want to access your server both from your desktop and laptop computer. Just repeat the steps above and add the two keys separately into your Lunanode account. Be careful to only add the public keys: they end with .pub
.
Provision your first VPS
Under Virtual Machines on the left panel, we are going to Create a new virtual machine. At the moment, there is only one region to choose from, so weâll place our node in Ontario.
In the next step weâll first give it a hostname. If you plan to point a domain name at your server, then that would make for a good hostname. Otherwise, anything descriptive will do, such as node or lnd.
The most difficult decision is what server we want to provision. The âmemory optimizedâ servers tend to be a good choice, as a bitcoin and Lightning node consume disproportionately more RAM than CPU power. And for the CPU-intensive syncronization process we can choose to pay for acceleration later.
The m.4 instance is probably a good minimum for a Lightning node. It is possible to run a node on an m.2 instance, but the node does not come with enough local storage to compile Bitcoin Core and LND.
Next, we are going to choose the operating system. Ubuntu 24.04 64-bit is what we are going to choose, but Debian 12 64-bit is very similar and will work just as well. Another popular option for professionally run nodes is CentOS 8 64-bit. Itâs important we are choosing an 64-bit operating system, or else we might crash our node once itâs channel.db reaches 2GB or more.
Finally we will select our SSH key or keys and provision our VPS by clicking on Create virtual machine.
Connect to your node over SSH
Under Virtual machines we should now see our VPS. After a minute or two, the yellow box should turn green, meaning our VPS is ready. We can see its External IP, as well as its IPv6. We can use either of them to connect to our node from our personal computer.
On our personal computer, we are going to open a terminal and type
ssh ubuntu@<our node's ip address>
For example
ssh ubuntu@172.81.181.220
If you are running into errors, you may have to specify the location and name of the SSH key you want to use:
ssh -i ~/.ssh/id_rsa <username>@<ip address>
As this is our first time connecting to our node, we are prompted with the message The authenticity of the host canât be established. We will continue to connect by typing yes
, but the next time we see that message we should be suspicious. This principle is called âTrust on First Useâ or Tofu.
The terminal should read:
Welcome to
Welcome to Ubuntu 24.04.3 LTS (GNU/Linux 6.8.0-31-generic x86_64)
We have successfully provisioned our server!
Attach a volume
Our server comes with some space on an SSD, but we might want to have more, especially for the Bitcoin blockchain. Luckily, we can buy additional space and attach it to our server.
Create the volume
First, we will power off our node. We are going to do that through the Lunanode dashboard. Under Virtual Machines we will select Manage, then Shut Down. We can verify that it is shut down by its status changing to Offline.
On the left of the screen, we find the option Volumes. We select our region (Toronto), give it a name (for example bitcoin
) and decide on a size. For a Bitcoin node that is used as a backend to our node, 50GB is a good size for a small node. Thatâs about 24 weeks worth of blocks. For a more performant node, 80GB or even 120GB might be a decent choice too. The entire blockchain takes up about 600GB today, and growing by about 2GB per week, so running a full archival node on a VPS might not be economical, as Lunanode will charge us US$36 per month for a 600GB large SSD.
We will leave the volume empty (Source) and create it.
The volume should appear instantly in our volume list. We will click on Manage and then Attach to VM where we select our node under Virtual Machine and virtio as a driver. This wonât work if our server isnât shut down. Only once our volume reads Attached to our node we can go back into Virtual Machines, then Manage, then Start Up our node. Once we can see Status changed to Online we can log back into our node with SSH.
Format the volume
We will log back into our node via SSH from our personal computer.
We can execute the following command to check if our volume is successfully attached:
lsblk
Typically, we will find it at the very bottom labelled vdc
. The main storage partition of our server is likely called vda
. You should be able to see their sizes too.
Next, we are going to format this SSD. We type and execute:
sudo mkfs.ext4 /dev/vdc
Depending on the size of your volume, this can be very fast or take a minute.
Now, we are going to permanently mount this volume. First we are going to create a directory called bitcoin
.
sudo mkdir /mnt/bitcoin
Next, we are going to mount the drive at this directory.
sudo mount /dev/vdc /mnt/bitcoin
We can see a list of all mounted volumes with the df
utility.
df -h
Finally, we are going to give permission over this new volume back to the user ubuntu, as it is initially owned by the root user.
sudo chown ubuntu:ubuntu /mnt/bitcoin
To make sure our server automatically mounts this volume when we start it, we are going to have to edit some configuration files.
First, we will find out the UUID of our SSD by running the following. If we canât see our drive, we have to reboot the machine with sudo reboot now
, then reconnect via SSH:
lsblk -f
Typically, the last line will show the mounted bitcoin disk. Look for vdc
under NAME and /mnt/bitcoin
under MOUNTPOINTS. A typical UUID looks like this: 50fb9f4-60e7-4024-adde-2a9959214dd6
.
Next, we are going to open the nano editor and edit the fstab
file:
sudo nano /etc/fstab
We are going to paste (right-click and paste or if your computer/mouse has one, the middle button) the following line:
UUID=<your SSD's UUID> <your mount path> ext4 defaults 0 0
For example:
UUID=050fb9f4-60e7-4024-adde-2a9959214dd6 /mnt/bitcoin ext4 defaults 0 0
Now are going to save the file with Ctrl
+ O
and exit the editor with Ctrl
+ X
.
We are going to test our configuration by mounting all the volumes.
sudo systemctl daemon-reload
sudo mount -a
If this succeeds without error, we can optionally reboot our server.
sudo reboot now
We will have to wait a minute for our server to reboot before we can log back in with SSH.
df -h
We should see something like the following.
Filesystem Size Used Avail Use% Mounted on
tmpfs 98M 996K 97M 2% /run
/dev/vda1 16G 2.0G 14G 13% /
tmpfs 486M 0 486M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/vdc 4.9G 24K 80G 0% /mnt/bitcoin
/dev/vda15 105M 5.3M 100M 5% /boot/efi
tmpfs 98M 4.0K 98M 1% /run/user/1000
You have successfully set up your VPS and attached a volume. Congratulations!