Nixos-rebuild: Permission denied (publickey,keyboard-interactive)

I successfully can login ssh admin@10.0.0.11 using my ssh key. However, nixos-rebuild fails

sudo nixos-rebuild  switch  --flake '.#envy' --upgrade --target-host admin@10.0.0.11 --use-remote-sudo
building the system configuration...
admin@10.0.0.11: Permission denied (publickey,keyboard-interactive).
error: failed to start SSH connection to 'admin@10.0.0.11'

Any clue what’s wrong here?

Seems I have to specify the key explicitly using NIX_SSHOPTS

NIX_SSHOPTS="-i ~/.ssh/id_ssh_admin@envy.ed25519" nixos-rebuild  switch  --flake '.#envy' --upgrade --target-host admin@10.0.0.11 --use-remote-sudo 

or

export NIX_SSHOPTS="-i /home/papanito/.ssh/id_ssh_admin@envy.ed25519" 
sudo -E nixos-rebuild  switch  --flake '.#envy' --upgrade --target-host admin@10.0.0.11 --use-remote-sudo 

Or you set the ssh key in your ssh configuration (system config programs.ssh.extraConfig or home-manager using programs.ssh.matchBlocks)

1 Like