How To Access Linux VPS Using SSH (No Password)
Tags: ssh, authentication, vps, server
Published: 2021-09-27 20:50:06

VPS (Virtual Private Server) are a type of server that can be easily purchased from hosting providers. VPS are virtual, which means they are not real physical servers. But surprisingly, most of the time you will not even notice it as you see their processors, memory and storage. In addition to that, the main significant difference between traditional hosting servers and VPS servers is the ability to customize everything as you need. No matter whether it is a software stack or hardware resources, you can adjust everything according to your requirements.

This guide will explain how to create a VPS in DigitalOcean and set up an SSH (Secure Shell) connection to access the VPS securely without using a password.

## Why Should We Use SSH?

SSH is a highly secure and reliable network communication protocol that can be used to log in to remote systems, execute commands and transfer files back and forth. Among many other useful features, SSH can also be used to securely log in to remote systems with or without using any password. No matter whether you have been using an insecure public WiFi hotspot in a cafe, SSH encrypts the entire communication without any additional effort.

## SSH Key Generation

We are using Ubuntu 20.04 LTS for this guide to generate SSH keys, but commands will be the same for all other Linux based distributions as well. Mac OS users will also be able to use the same commands. Windows users can use a GUI client like [Putty](https://www.putty.org/).

First, open the application launcher by clicking the icon in the left bottom corner.

![Ubuntu 20.04 LTS Applications Menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3szm3l9c6u8tzw5brx44.png)

Search for “terminal” and press enter. You will also be able to open the terminal using the shortcut keys by pressing “Control” + “Alter” + “T” at the same time.

![Ubuntu 20.04 LTS Applications Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xt4iiypccjknme2sjsju.png)

Now you will be able to see a terminal window. We are using this terminal to type commands.

![Ubuntu 20.04 LTS Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i0hva48r5n4f9ee81930.png)

Type the following command and press enter.

```
ssh-keygen
```

By default, it will use the key type as RSA. But there are many other key types like “dsa”, “ecdsa”, “ecdsa-sk”, “ed25519”, “ed25519-sk”. You can use something like “ed25519”, which is considered more secure than RSA like mentioned below. But it is optional and it doesn’t mean RSA is insecure or outdated.

```
ssh-keygen -t ed25519
```

It will ask for a path and key name, if you need you can mention it or otherwise you can simply press enter to use the default path and name.

![Ubuntu 20.04 LTS Terminal ssh-keygen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjldra0y9qdegwhtdhqh.png)

Again, it will ask for a password. We can protect our private key with a password for additional security. So, even someone stolen your keys, they will not be able to use them without the password. If you don't need it, simply leave them blank by pressing enter key twice.

If you are new to the Linux terminal, you might be wondering why it doesn’t indicate when you type the password. But you don’t need to worry about it, that is how it is.

![Ubuntu 20.04 LTS Terminal ssh-keygen password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5zjcqpngrpbyquz1zd3.png)

After that, SSH key pair will be generated and stored in the ".ssh" directory of your home directory. You can list them by using the "ls" command.

```
ls ~/.ssh
```

You will see two files named "id_rsa" and "id_rsa.pub". "id_rsa" is the private key, DO NOT share the private key(s) with anyone. "id_rsa.pub" is the public key, which is safe to share.

![Ubuntu 20.04 LTS Terminal ssh-keygen complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bphfkvte528tbvgfv07m.png)

Type the following command, it will show the content in your public key. Select the content of the key and copy it, we need it later.

![Ubuntu-20.04 LTS Terminal ssh-keygen cat public key selected](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhqvhfx0220hnkx9s2lc.png)

## SSH Key Setup

We are using DigitalOcean for this guide, but this process will be similar to other VPS hosting providers like Vultr, Linode as well. Go to Settings > Security and press “Add SSH Key”. If you are using Vultr, it is in Account > SSH Keys.

![Digitalocean add ssh public key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uug7kb2ae3iky5ezr6do.png)

Now paste the previously copied SSH key in to "SSH key content" box. Also, give it a name.

![Digitalocean add ssh public key and name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jzdulkcsi65t4tymuw9.png)

You will be able to see that the public key has been successfully added to your DigitalOcean account. Remember, currently, this key is in your DigitalOcean account and not in a VPS. We need to add this key to VPS.

![Digitalocean add ssh public key added](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/htss3z4c37ie059un023.png)

## Create A New Project

DigitalOcean has a feature called "Projects" which will be helpful when you manage multiple projects. Click the "New Project" link in the sidebar to create a new project.

![Digitalocean create project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgewmnofxpl9rb28ew1p.png)

Click "Skip for now".

![Digitalocean create project skip for now](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fhdit4fmnlcohjue2na.png)

## VPS Creation

Now we are going to create the VPS. In DigitalOcean, it is called a "Droplet".

![Digitalocean create droplet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7evtztg0aqlspb4h1v3.png)

First, you need to select an OS (Operating System) and version you need for the VPS.

![Digitalocean create droplet select operating system](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yathxb3ws9eu3c6a61jr.png)

There will be multiple hardware configurations, we are using the first option for this guide.

![Digitalocean create droplet select price](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gexfef9uybk03g9nrj4x.png)

Select a location for your VPS.

![Digitalocean create droplet select region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5dendgtzduvyrilfyy0.png)

This step is very important, now you should be able to see the SSH key which we added, previously. Make sure to select it. Otherwise, you will have to manually add it using the terminal.

![Digitalocean create droplet select ssh key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kd467gf0gc2xop9qr221.png)

Give your VPS a hostname, kind of like a name to identify it.

![Digitalocean create droplet hostname](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zm2dc8myyuaxg6hbrbxo.png)

Make sure everything is correct and then press "Create Droplet".

![Digitalocean create droplet submit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jj71753d9dofcx11ple.png)

It will take few minutes to build the droplet. Meanwhile, you can see the progress.

![Digitalocean create droplet progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sqx0ipmqzyjzvv3r97i.png)

Once it is created, click on it to expand it. You will be able to see its IP address. Copy the IP address, we need it to log in to the VPS.

![Digitalocean droplet ip v4 address](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhxdd9nvdkxnvrq8ycg7.png)

## Log In Using SSH

Again, get back into the terminal of your computer, type the following command. Make sure to replace “your_ip_address_here” with your IP address.

```
ssh root@your_ip_address_here
```

When you are connecting to the VPS for the first, you will have to confirm it. Type "yes" and press enter.

![Ubuntu 20.04 LTS Terminal ssh ecdsa key fingerprint confirmation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6jp555lontw1fx21lh7.png)

You have successfully logged in to the VPS. In "root@ubuntu-vps:~#" you can see that you have logged in as the "root" account. It is the most powerful and privileged user in your VPS. Now you can install/uninstall software or do whatever you want.

![Ubuntu 20.04 LTS Terminal ssh vps connected](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzwesvog4knrgf4mujzv.png)

Usually, the very first thing that we need to do when we logged in to a newly created VPS is updating its software list. Type following command, it will take few seconds.

```
apt update
```

Now type the following command to upgrade all the software installed in the VPS. It will show a list of software that has an update, the total data that need to be download and the required disk space for the upgrade.

```
apt upgrade
```

Press enter to continue.

![Ubuntu 20.04 LTS Terminal ssh vps apt upgrade](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rantal79tsl96e8p16e.png)

This process can take few minutes and the progress will be displayed.

![Ubuntu 20.04 LTS Terminal ssh vps apt upgrade progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y32di3ef7l4jcjeygh46.png)

## Disconnect The SSH Connection

Once you did what you need, you can terminate the SSH connection by typing "exit" in the terminal.

![Ubuntu 20.04 LTS Terminal ssh vps disconnected](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wqljk9p16ujymm67ql74.png)

## Destroy The VPS

If you no longer use the VPS, consider deleting it. Because most hosting providers charge for the time you keep it, including DigitalOcean.

Open the droplet menu and click "Destroy".

![Digitalocean droplet menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu5p9uo6drrw9a4oakqe.png)

Click "Destroy this Droplet".

![Digitalocean droplet destroy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ixxwnfmhiquw91rw3k5.png)

You will have to confirm the VPS deletion for the last time. After this, all the data will be deleted and will not be able to recover. Make sure that you are destroying the exact droplet.

![Digitalocean droplet destroy confirm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cvchtz9swv26wl4y7k5u.png)

## Conclusion

In this beginner-friendly guide, we explained the advantages of using a password-less SSH connection to access VPS. Then we created an SSH key pair and a VPS. After that, we used that key pair to successfully log in to the VPS we created without using a password. What do you think about this guide? Did you find something confusing or need to add something to the discussion? Let’s discuss this in the comments section.

Also, feel free to visit [devtonight.com](https://devtonight.com) for more related content.