How to enable passwordless SSH login on Ubuntu 20.04 that's inside Multipass

; Date: May 31, 2020

Tags: Ubuntu »»»» Multipass

Multipass is an excellent tool for running Ubuntu on macOS or Windows laptops. Out of the box it does not enable passwordless SSH access to the Ubuntu instance, and instead you use the multipass shell command. Sometimes you need passwordless SSH access, however.

In my case I want to experiment with remote control access to Docker. To do this requires passwordless access to a Linux instance that's running Docker. What passwordless SSH means is to install ones "SSH Key" as an authorized key for a remote system. At that point you're able to use SSH to access that remote system, without it asking you for a password.

Multipass has the multipass shell command that starts a login session inside the Multipass instance. For most intents and purposes that is fine, and I have been using Multipass for months without needing any other access method.

Out of the box this is what results:

$ ssh ubuntu@
The authenticity of host ' (' can't be established.
ECDSA key fingerprint is SHA256:+rBEXAMPLEb2MREXAMPLE4+mOukYDtkoJ4EXAMPLExs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (ECDSA) to the list of known hosts.
ubuntu@ Permission denied (publickey).

We know from using Multipass Ubuntu instances, that the default user account is named ubuntu, and that Multipass assigns an IP address to the instance. That IP address can be used for example to access a service hosted inside the instance. But, as you can see, Multipass instances are not configured to allow this. Further, we do not know what the password of that Ubuntu user account is.

Any time you see Permission denied (publickey) as the response to using SSH to access a system, it means your public key is not valid with that remote system. The universal cure is to add your public SSH key to the authorized keys of the remote system. That it's a Multipass instance doesn't make any difference, because the cure is the same.

Why do we need passwordless SSH? I've survived for months using Multipass without this. But consider an example in another post, Use Canonical's Multipass to display Linux desktop on macOS desktop and VNC, where I discuss setting up an SSH tunnel to assist running VNC.

$ ssh -L 5901: -C -N -l ubuntu YOUR-SERVER-IP-ADDRESS

There are all sorts of uses for SSH tunnels, not just for setting up VNC access. And, there are many tools will use an SSH URL, like ssh://user-name@server-name, to access a service. In other words, it depends on what you're doing in an Multipass instance as to why or whether you need passwordless SSH access.

Setting up passwordless SSH for a Multipass instance

This is so trivially easy to implement.

First off, you must have an SSH key. If you're using a Linux or macOS machine, an SSH key is easily generated using the ssh-keygen tool. For Windows, well, I was about to say that SSH is not easily available for Windows, but I see that ( OpenSSH is available in Windows 10 since October 2018. Cool. Microsoft is perhaps changing to not be the bad Microsoft of old.

At this point I'm assuming you have already run ssh-keygen and have an SSH key.

$ ls ~/.ssh
authorized_keys   id_rsa     known_hosts

The file contains your public key. The authorized_keys file contains the public keys that are allowed to access the computer.

An SSH public key looks like this:

 cat ~/.ssh/ 

This is not a real SSH key, but a modified one. But once you have this block of text, you log in to the remote computer. In this case:

$ multipass shell swarm1
$ ls .ssh

Then, you simply edit that file and paste in the text of your SSH key.

You then save that file, and log out of the Multipass instance. BTW, these instructions work for any remote computer that uses OpenSSH, not just Ubuntu running inside Multipass.

$ multipass list
Name                    State             IPv4             Image
swarm1                  Running     Ubuntu 20.04 LTS

Once you've done that, you can run:

$ ssh ubuntu@

And you will log-in to the Multipass instance without requiring a password.

About the Author(s)

David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.