Default login and password for NixOS

Used this $HOME/configuration.nix from the about page

{
  boot.loader.grub.device = "/dev/sda";
  fileSystems."/".device = "/dev/sda1";
  services.sshd.enable = true;
}

to build a VM

NIXOS_CONFIG=$HOME/configuration.nix nixos-rebuild build-vm

After booting the VM I duno which login and password works… Does someone know ?

The manual shows

You are logged-in automatically as nixos . The nixos user account has an empty password so you can use sudo without a password.

(Not sure if it is for the ISO or a new build with nixos-install/nixos-rebuild)
Searched all other occurrences of “login” within nixos manual without any success.

I know that for the OVA (VM image) the login is “demo” and the password is “demo” …

see here:
https://nixos.org/nixos/manual/index.html#sec-changing-config

The VM does not have any data from your host system, so your existing user accounts and home directories will not be available unless you have set mutableUsers = false . Another way is to temporarily add the following to your configuration:

users.users.your-user.initialHashedPassword = “test”;

Important: delete the $hostname.qcow2 file if you have started the virtual machine at least once without the right users, otherwise the changes will not get picked up. You can forward ports on the host to the guest. For instance, the following will forward host port 2222 to guest port 22 (SSH):

$ 

QEMU_NET_OPTS=“hostfwd=tcp::2222-:22” ./result/bin/run-*-vm

allowing you to log in via SSH (assuming you have set the appropriate passwords or SSH authorized keys):

$ 

ssh -p 2222 localhost

also if you want to ssh as root, you’ll need to set
services.openssh.permitRootLogin = true;

Thanks. I will go for

users.users.your-user.initialHashedPassword = “test”;

Although I still wonder why I have a prompt asking for a login if there is no user in the VM OS.

your-user in the line you quoted is the user

1 Like

You mean/want initialPassword

Or use mkpasswd program to get hash

1 Like