Learning: Creating a Ubuntu Droplet
Source: Dev.to
Introduction
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.
Creating an SSH Key on Ubuntu
The following tutorials explain how to create an SSH key on your local computer:
- DigitalOcean tutorial: How to configure SSH key‑based authentication on a Linux server
- Bizanosa blog post: Ubuntu 22.04 initial server setup (Vultr)
Tip: Create a dedicated directory for each project before generating keys. This isolates keys, making it easier to delete or recreate them without affecting other environments.
Example commands
# Create a directory for the project
mkdir -p ~/ssh-keys/sushi-project
cd ~/ssh-keys/sushi-project
# Generate a new SSH key pair
ssh-keygen -t ed25519 -C "your_email@example.com" -f id_ed25519
Setting Up the DigitalOcean Droplet
Spinning up a droplet in DigitalOcean is straightforward. After the droplet is created, you’ll need to copy your public key to the server.
Troubleshooting SSH Connection Issues
During my first attempt I encountered the error:
Fail to copy due to error: port 22: Connection refused
The cause was that the SSH server was not running on my local machine. The following steps resolved the issue:
# Allow SSH through the firewall
sudo ufw allow 22
# Start and enable the SSH service
sudo systemctl start ssh
sudo systemctl enable ssh
Verify that the service is running:
sudo netstat -anp | grep sshd
For more details, see the discussion on Ask Ubuntu: “Why am I getting a port 22 connection refused error?”.
Copying the SSH Key to the Droplet
Use ssh-copy-id to transfer your public key to the remote server:
ssh-copy-id -i /path/to/your/id_ed25519.pub user@remote-host
# or
ssh-copy-id -i /path/to/your/id_ed25519.pub user@remote-ip
Connecting to the Droplet
After the key is copied, connect with:
ssh root@remote-ip -i /path/to/your/id_ed25519
Bonus: Verify the Key Installation
To confirm that the key was added correctly, inspect the authorized_keys file on the droplet:
cat ~/.ssh/authorized_keys
You should see the contents of your local public key listed.