How to Create a Virtual Machine on DigitalOcean and Securely Access it using SSH Keys and RDP
DigitalOcean is a cloud hosting provider that offers an easy-to-use interface for creating and managing virtual machines (VMs) in the cloud. In this blog post, we will cover the steps for creating a VM instance, configuring SSH keys for secure access to the VM, accessing the VM using SSH, adding custom firewall rules, installing RDP on the VM, and hosting files using a simple HTTP server.
1.Register and Create a VM Instance First, register on the DigitalOcean website and log in to your account. From the dashboard, click on the “Create” button and select “Droplets.” Choose the operating system and plan you want for your VM instance, and select a data center region. Finally, click on the “Create” button to create your VM instance.
2. Configure SSH Keys for Secure Access to the VM After the VM instance is created, click on its name to open its configuration page. Scroll down to the “Authentication” section and select “Add SSH Keys.” Copy and paste your SSH public key in the provided box or upload a file containing your public key.
Click on “Add SSH Key” to add your key to the VM instance.
3. Access the VM Using SSH To access the VM using SSH, you can access using cloud platform or from your terminal:
Accessing from terminal:
ssh root@<droplet’s public ip address>
4. Add Custom Firewall Rules in the Subnet’s Security List To add custom firewall rules, click on the “Networking” tab and select the “Security” option. Click on the “Create a Firewall” button and set the firewall name and rules according to your needs. Once the firewall is created, click on the “Assign” button to assign it to your VM instance.
5. Install RDP on the VM and Access it Using RDP from Your PC To install RDP on the VM, run the following commands on the VM command line:
adduser (username)
usermod -aG sudo (username)
sudo apt update
sudo apt install xubuntu-desktop
sudo apt install xrdp
sudo systemctl status xrdp
sudo adduser xrdp ssl-cert
sudo ufw allow 3389
Once RDP is installed, you can access the VM desktop from your local computer using an RDP client. For Windows, you can use the built-in Remote Desktop Connection app.
6. Host Files Using a Simple HTTP Server and Access Them Using the Public IP To host files using a simple HTTP server, install a web server such as Apache on the VM by running the following commands:
sudo apt-get update
sudo apt-get install apache2
After the web server is installed, change your directory to web server’s root directory and access the “index.html” file
cd /var/www/html
nano index.html
Once the files are hosted, you can access them using the VM’s public IP address from a web browser.
Files are hosted which can be confirmed by RDP:
Conclusion DigitalOcean provides an easy-to-use interface for creating and managing VM instances in the cloud. By following the steps outlined in this blog post, you can create a VM instance, configure SSH keys for secure access, access the VM using SSH, add custom firewall rules, install RDP, and host files using a simple HTTP server. These steps will help you get started with DigitalOcean and securely access your VM instances in the cloud.