Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: How to connect with different user after reboot? #409

Closed
gabyx opened this issue Oct 15, 2024 · 7 comments
Closed

feat: How to connect with different user after reboot? #409

gabyx opened this issue Oct 15, 2024 · 7 comments

Comments

@gabyx
Copy link

gabyx commented Oct 15, 2024

I have VM that has a user ubuntu.

I can run nixos-anywhere --flake ... 11.11.11.11 (which actually works on engine.switch.ch which is really great). The ~/.ssh/config is:

Host 11.11.11.11
    IdentityFile ~/.ssh/vm
    IdentitiesOnly yes
    User ubuntu

However once it reboots -> I can no longer connect because the user changed to root =). It works if I in the meantime change the User ubuntu to User root.

Is there a way to somehow trick nixos-anywhere to use root after install or some other ssh options?

@gabyx
Copy link
Author

gabyx commented Oct 15, 2024

Or even maybe nixos-anywhere could provide an option: --post-kexec-ssh-user or even --post-kexec-ssh-hostname where the later gives the opportunity to use --post-kexec-ssh-hostname afterinstall with an ~/.ssh/config as;

Host 11.11.11.11
    IdentityFile ~/.ssh/vm
    IdentitiesOnly yes
    User ubuntu

Host afterinstall
    IdentityFile ~/.ssh/vm
    IdentitiesOnly yes
    User root

Would a PR be welcome on this? What would you reckon is a good solution?

@gabyx gabyx changed the title question: How to connect with different user after reboot? feat: How to connect with different user after reboot? Oct 15, 2024
@sedlund
Copy link
Contributor

sedlund commented Oct 15, 2024

It should kexec onto the new kernel (this is not a reboot) and nixos-anywhere will reconnect to the machine using generated ssh keys from prior to kexec and install nixos. is this not happening?

your nixosConfiguration flake should have configured the user and ssh key (if that is your method to connect) to use after reboot.

by after reboot am I correct to think that NixOS is installed at this point? If that is the case nixos-anywheres job is complete.

@gabyx
Copy link
Author

gabyx commented Oct 15, 2024

your nixosConfiguration flake should have configured the user and ssh key (if that is your method to connect) to use after reboot.
Jeah: My ssh config is the same as https://github.com/nix-community/nixos-anywhere-examples/blob/main/configuration.nix#L26

First I do nixos-anywhere --flake ubuntu@host and then the installation after kexec fails to reconnect, I can leave it trying to reconnect -> and change User to root in the .ssh/config and then it suddenly works and I see all nix store paths getting copied and the install finished successfully =)

@sedlund
Copy link
Contributor

sedlund commented Oct 15, 2024

please provide the full logs with --debug enabled along with the command you are running.

it should be trying to reconnect with the user provided to install as and using the generated key that it installed.

you can try to debug why ssh is not allowing login by logging in yourself after kexec and looking at the ssh logs.

the nixos-anywhere key will be inserted into ~ubuntu/.ssh/authorized_keys via ssh-copy-id the private key on the installer machine will be in /tmp/tmp.SOMEWHERE you will see when you run it with --debug.

@sedlund
Copy link
Contributor

sedlund commented Oct 15, 2024

you should not be having this

IdentitiesOnly yes

EDIT strike that. it should be ok.

@gabyx
Copy link
Author

gabyx commented Oct 18, 2024

@sedlund : Ah thanks a lot!

@gabyx
Copy link
Author

gabyx commented Oct 18, 2024

See #411. Thanks.

@gabyx gabyx closed this as completed Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants