DEV Community

Gurlal Sidhu
Gurlal Sidhu

Posted on

Why Isn't SSH Working on Your New Ubuntu Machine?

The simple answer is that newer versions of Ubuntu or some Linux distributions may not have OpenSSH installed by default. So, it's up to us to check, set it up, and create a SSH key to connect.

Connect to machine via terminal and setup SSH using the steps below:

1. Check if SSH is installed on the machine

Run the command below to verify SSH version:
ssh -V

An Output like the one below suggests OpenSSH is installed:
OpenSSH_9.4p1, LibreSSL 3.3.6

If OpenSSH is installed, skip to step 3.

2. Install OpenSSH

If it is not installed, install it on a Debian-based distribution using the command below:
sudo apt openssh-server

3. Ensure SSH service is running and enabled

Even tho OpenSSH is installed, SSH service may not be running or enabled. First check its status with the command below:
systemctl status ssh

If the service isn't not running, run the following command to start it:
systemctl start ssh

4. Allow SSH through the firewall

Even if SSH is installed and running, it might not be allowed by the firewall. To allow SSH through the firewall, use the following command:
sudo ufw allow ssh

5. Generate an SSH key on the host machine

With SSH installed, the service running, and the firewall configured, generate a key pair on the host machine that you'll use to SSH into the new machine. Generate the key using the following command:

This command will create two keys: a private key and a public key. Keep the private key secure and do not share it with anyone. Upon running the command, you will be asked to name the key and choose a location to store it. You can also add a password for added security.

6. Copy the public key to the Ubuntu machine

Move the public key to the Ubuntu machine using the following command:
ssh-copy-id -i <keyname>.pub username @ machinename

7. Connect via SSH

Now that your new machine is set up with the SSH service running and the public key added, you can establish an SSH connection using the following command:
ssh -i keylocation/keyname user@machinename or IP

Top comments (0)