Document
Ubuntu 20.04 Desktop

Ubuntu 20.04 Desktop

introduction Ubuntu 20.04 Desktop does not include an SSH server preinstalled. In this article, I show how I installOpenSSH, create an SSH keypair, i

Related articles

What is a Cloud Kitchen? Meaning, Advantages, and Startup Insights Benjamin Moore Chantilly Lace Cut in half: On Cloudhorizon Waterproof Review (2024) Remote Access VPN: How It Can Benefit Home and Business Users Manila Climate, Weather By Month, Average Temperature (Philippines)

introduction

Ubuntu 20.04 Desktop does not include an SSH server preinstalled. In this article, I show how I installOpenSSH, create an SSH keypair, installthe keypair Ubuntu for a user and disable password-based SSH logins. I also include a PowerShellscript to mimic the base features ofssh-copy-id. This article also applies to configuring OpenSSH that is preinstalled on cloud servers from AWS, Azure, Google, and probably most vendors.

There are many articles on the Internet about installing and setting up OpenSSH. This article documents my steps for my own documentation purposes. I am currently writing a series ofarticles on Laravel 9 with a focus on storage and mail. My objective is to create recipes for installing and setting up everything related to Laravel 9, PHP 8.1, and Ubuntu run in a Hyper-V VM and in the cloud on Azure and Google Cloud VMs.

My environment:

  • Windows 10 Professional for development. This system is the SSH client connecting to Ubuntu run OpenSSH.
  • Hyper-V virtual machine run Ubuntu 20.04 Desktop.
  • Hyper-V virtual machine run Ubuntu 20.04 Server.
  • Azure Virtual Machine run the imageCanonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest.
  • Google Cloud Compute Engine is run run the imageubuntu-2004 – lts .

Update the Operating System

sudoaptupdate

sudoaptupgrade y

sudoreboot

After updating the operating system, I always reboot the OS. I am not sure if this is really necessary, but I want to ensure that all processes are using the latest code.

Install OpenSSH Server

installOpenSSH server :

sudoaptinstallopensshserver y

Verify that the OpenSSH server is now run:

sudosystemctl status ssh

 

output:

ssh.service OpenBSDSecure Shellserver

    load: loaded (/lib/systemd/system/ssh.service; enable; vendor preset: enable)

    active: active (run) sinceSun 20211212 12:34:00 PST; 48 ago

...

Determine Ubuntu’s IP address

ip addr

 

output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state unknowngroup default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scopehost lo

       valid_lftforeverpreferred_lftforever

    inet6 : :1/128 scopehost

       valid_lftforeverpreferred_lftforever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

    link/ether 00:15:5d:00:34:10 brd ff:ff:ff:ff:ff:ff

    inet 192.168.10.149/24 brd 192.168.10.255 scopeglobal dynamicnoprefixroute eth0

       valid_lft 85618sec preferred_lft 85618sec

    inet6fe80: :797c:7f49:160f:cd69/64 scopelink noprefixroute

       valid_lftforeverpreferred_lftforever

For my setup, the IP address is 192.168.10.149.

SSH Connect Test

Test connecting to Ubuntu using SSH. I set up Ubuntu with the username jhanley. Update the sshcommand with your username and IP address.

sshjhanley@192.168.10.149

 

output:

Theauthenticity ofhost ‘ 192.168.10.149 ( 192.168.10.149 ) ‘ can‘ t be establish .

ECDSA keyfingerprintis SHA256:DWy/Xszu/Xak8ZbPkzuH+MDTGFTFmqLpYhBkMT/3m0A.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added ‘192.168.10.149‘ (ECDSA) to the list ofknown hosts.

jhanley@192.168.10.149 ‘s password:

welcometo Ubuntu 20.04.3 LTS (GNU/Linux 5.11.041genericx86_64)

For my Ubuntu installation , the UFW firewall is is is not active . You is need may need to allow the SSH port :

Setup SSH Keypair Authentication

I recommend switching from password-based logins to SSH keypairs. Digital Ocean wrote a nice article on this topic. I used the following steps on my Windows 10 desktop.

Create an SSH keypair:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

sshkeygen f C:\Users\john.hanley\.ssh\ubuntudesktop t rsa b 4096 N “”

 

output:

Generating public/private rsa keypair.

Youridentificationhas beensavein C:\Users\john.hanley/.ssh/ubuntudesktop.

Yourpublic keyhas beensavein C:\Users\john.hanley/.ssh/ubuntudesktop.pub.

Thekeyfingerprintis:

SHA256:GUbRq7aS4+Yj8YtgPXvhgcPRfNNICKJsmkftqQoaLJ0 john.hanley@desktopNUC

Thekeys randomart imageis:

+[RSA 4096]+

|  . .. .oo       |

|.. o  ... .      |

|.o. .o .oo .     |

|oo ...o.+oo      |

|o ..oo .So       |

|.o += o o        |

|+.E o= = .       |

|+ + ..+X .        |

|o   o*+=         |

+[SHA256]+

Copy/Install the SSH keypair 

Windows 10 does not have the equivalent ofthe Linux ssh-copy-id command. I wrote a PowerShellscript that installs the SSH public keyonto Linux. Create a file named ssh-copy-id.ps1 and enter the following script.

I also wrap the PowerShellscript with a batch script:

Execute the PowerShellscript to copy the SSH public keyto the user’s .ssh/authorized_keys file.

powershell ./sshcopyid.ps1 C:\Users\john.hanley\.ssh\ubuntudesktop.pubjhanley@192.168.10.149

Verify that the SSH login now works using a keypair.

ssh i c:\users\john.hanley\.ssh\ubuntudesktop.pubjhanley@192.168.10.149

 

output:

welcometo Ubuntu 20.04.3 LTS (GNU/Linux 5.11.041genericx86_64)

 

* Documentation:  https://help.ubuntu.com

* Management:     https://landscape.canonical.com

* support:        https://ubuntu.com/advantage

 

0 updatecan be applied immediately.

 

YourHardware Enablement stack (HWE) is supported untilApril 2025 .

Lastlogin: SunDec 12 13:50:44 2021 from 192.168.10.135

Setup .ssh / config

TheCLI command sshsupports reading host authentication information in the file ~/.ssh/config.

Edit or create the file config in the .sshdirectory. For my Ubuntu desktop configure above, add the following section:

Host ubuntudesktop

    HostName 192.168.10.149

    User jhanley

    identityfile ~/.ssh/ubuntudesktop

Now I is connect can connect to the Ubuntu system with a simplified command :

sshubuntudesktop

 

output:

welcometo Ubuntu 20.04.3 LTS (GNU/Linux 5.11.041genericx86_64)

 

* Documentation:  https://help.ubuntu.com

* Management:     https://landscape.canonical.com

* support:        https://ubuntu.com/advantage

 

0 updatecan be applied immediately.

 

YourHardware Enablement stack (HWE) is supported untilApril 2025 .

Lastlogin: SunDec 12 17:55:54 2021 from 192.168.10.135

disable Password – base SSH authentication

Before complete this step , make sure you can log in using your SSH keypair .

Edit the file /etc/ssh/sshd_config with elevated permissions (sudo). Change the following line to be:

PasswordAuthentication no

reload the OpenSSH server :

sudosystemctl reload ssh

Verify that the OpenSSH server is run without errors:

sudosystemctl status ssh

 

output:

ssh.service OpenBSDSecure Shellserver

    load: loaded (/lib/systemd/system/ssh.service; enable; vendor preset: enable)

    active: active (run) sinceSun 20211212 12:34:00 PST; 48 ago

...

As an extra security measure, I reboot the OS to ensure existing connections are terminated.

Another method to terminate all SSH sessions without rebooting:

sudokillallsshd

sudosystemctl start sshd

additional Information

summary

Installing and setting up OpenSSH on Ubuntu 20.04 Desktop is straightforward. Switching from password to SSH keypair-based logins improves security. Since Windows 10 does not have the program ssh-copy-id, I wrote my own PowerShellscript to duplicate the features I require.

photography credit

I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Pixabay at Pexels.

I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.

For the past 14+ years, I have beenworking in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.