Can ssh as root but cannot nixos-rebuild switch

I have a server which I am able to ssh into as root.

ssh root@myHost
Last login: Mon Apr 29 21:42:54 2024 from


Recently though (this definitely used to work) I cannot deploy to this server using nixos-rebuild switch.

sudo nixos-rebuild switch --flake .#myFlake --target-host root@myHost                                                 
building the system configuration...
root@myHost: Permission denied (publickey,keyboard-interactive).
error: failed to start SSH connection to 'root@myHost'

Its saying that I can’t authenticate the ssh connection which doesn’t make sense because I can ssh into the server just fine.

What does this mean?

1 Like

Try without sudo, it’s trying to use ssh key from your local root account

1 Like

Ok that was embarrassingly simple! Thanks so much!