canonical / multipass

Multipass orchestrates virtual Ubuntu instances
https://multipass.run
GNU General Public License v3.0
7.76k stars 642 forks source link

Inability to SSH in as root #3494

Closed computershateme closed 5 months ago

computershateme commented 5 months ago

Describe the bug Inability to SSH in as root

To Reproduce

  1. Set /etc/ssh/sshd_config to allow root login and restart ssh on instance
  2. Run the command sudo multipass exec instance-name -- bash -c "echo cat path/to/id_rsa.pub >> /root/.ssh/authorized_keys” on host, get back an empty line
  3. Try to login as root: sudo ssh -X root@xx.xx.xx.xx get back "SSH Permission denied (publickey)"

Expected behavior SSH into instance as root user

Logs Please provide logs from the daemon, see accessing logs on where to find them on your platform.

Additional info

Additional context Add any other context about the problem here.

andrei-toterman commented 5 months ago

Hey, @computershateme! What you want to do should be entirely possible. Are you sure the key did actually end up in /root/.ssh/authorized_keys? Just to clarify, do you want to log in as root using your own user's key or does the root user on your system have a key that you're trying to use? If it's the former, try this:

multipass exec instance-name -- sudo bash -c "echo `cat ~/.ssh/id_rsa.pub` >> /root/.ssh/authorized_keys"

if it's the latter, try this:

multipass exec instance-name -- sudo bash -c "echo `sudo cat /root/.ssh/id_rsa.pub` >> /root/.ssh/authorized_keys"
computershateme commented 5 months ago

Awesome, thank you so much. Apparently my keys were not getting through to the root user because I wasn't putting the sudo in front of bash or cat. Thank you and you can close this ticket.

andrei-toterman commented 5 months ago

I'm glad it worked!