Uncommenting AuthorizedKeysFile in sshd_config blocks access of multipass to my instance

Hello,

I just installed a new multipass instance, and I observed that if I uncommnet
#AuthorizedKeysFile ~/.ssh/authorized_keys
then I cannot connect anymore to the instance I created. This happens after a restart of the instance.
Is this a bug? Shouldn’t I uncomment this line? I did it in order to provide keys for ssh. Am I doing something wrong here? It does not look like, but blocking completely the access to the instance is not expected.

Error sample:

multipass info linux1
info failed: ssh failed to authenticate: ‘Access denied for ‘publickey’. Authentication that can continue: publickey’

Please provide any input.

Thanks!

Hi @smecher, the best way to add an SSH key to Multipass instances is to use cloud-init.

Something along those lines is the simplest case:

$ multipass launch --cloud-init - <<EOF
ssh_authorized_keys:
- $( cat ~/.ssh/id_rsa.pub )
EOF

As to why your case didn’t work, that path is searched by default, so you don’t need to include it in your config, but more importantly, ~ isn’t expanded to your home directory. See ssh documentation on the the topic.

Thank you! This really helped!

I recently got the same error too. Here is what caused the error:

  1. I launched an instance successfully and logged into it with multipass shell <instance_name>
  2. Then I inadvertently overwrote all the files in ~/.ssh/ of the host computer (not the instance).
  3. All multipass commands with regard to this instance were failing with this same error

Fortunately, I was still logged into the instance and I could log in via ssh ubuntu@<instance_ip> - I had a chance to manually copy my public key into authorized_keys file. Here is how I resolved the issue:

  1. I created a new instance and logged into it.
  2. I copied the only key in ~/.ssh/authorized_keys
  3. I then pasted this key into ~/.ssh/authorized_keys of the first instance.

Problem solved. I could now safely delete and purge the second instance.