The next step of my Sushi Project (Coming soon) was finding a cloud provider. Since I’m based in Europe and my customer is in Brazil, I needed a solution that guaranteed 24/7 uptime across regions.
We decided to move forward with a DigitalOcean (DO) Ubuntu Droplet.
To maximize efficiency, I needed to connect my local machine to the remote server. The first step was adding my SSH Key to the VM to ensure a secure, seamless connection.
But how to create a SSH key in your ubuntu?
This tutorial together with this blog post shows how to create a ssh key in your local computer.
One great tip I picked up from the Bizanosa blog was to create specific directories before generating SSH keys. This approach allows you to manage independent keys for different projects.
I highly recommend this because as you juggle different environments, you may need to delete and recreate keys multiple times. By isolating them in their own folders, you gain a bigger margin for error—you can wipe a specific setup without accidentally breaking your other connections.
Once the SSH key is created, the next step is to spin up a droplet in DigitalOcean. While the droplet creation process in DO is extremely intuitive, connecting your local machine to the VM can be a bit tricky if you only follow the standard documentation.
To bridge that gap, I followed this video tutorial by Bizanosa. It provided a much clearer walkthrough on how to generate the key and use the -i flag to specify the private key identity when logging in for the first time.
During my SSH Key connection I had this error:
Fail to copy due to error: port 22: Connection refused
This happens because didn't have any SSH Server running in my local machine. So I could not accept the connection. In this forum the error is detailed described and offered some solutions.
I did the "sudo ufw allow 22", adding firewall rules but not activate right away. Then, I needed to manually activate them, by running:
sudo systemctl start ssh
sudo systemctl enable ssh
After it, I could validate that it is running by:
sudo netstat -anp | grep sshd
Now, I am able to copy it to my droplet:
ssh-copy-id -i {ssh key path in your local computer} {user}@{remote host}
or
ssh-copy-id -i {ssh key path in your local computer} {user}@{remote IP}
Once copied, I was able to connect to the VM by running this command:
ssh root@{remote IP} -i {ssh key local path}
BONUS:
If you like to confirm that the process was successfully done, you can find the authorized_keys file and see if your local key if there.
Top comments (0)