|
49 | 49 | services.openssh.enable = true; |
50 | 50 | services.openssh.settings = { |
51 | 51 | PermitRootLogin = "no"; |
52 | | - PasswordAuthentication = true; # simple first boot; change to keys-only if you want |
| 52 | + PasswordAuthentication = true; # disabled in practice until configurator sets a real user password |
53 | 53 | }; |
54 | 54 |
|
55 | 55 | # Enable console on HDMI (keeps display active and shows login prompt) |
|
80 | 80 | isNormalUser = true; |
81 | 81 | extraGroups = [ "wheel" ]; # wheel = sudo access |
82 | 82 |
|
83 | | - # Option 1: Set initial password (plaintext - stored in /nix/store) |
84 | | - # User can change it after first login with 'passwd' |
85 | | - initialPassword = "lnbits"; |
86 | | - |
87 | | - # Option 2: Use a hashed password (more secure - see example below) |
88 | | - # hashedPassword = "$y$j9T$...your-hashed-password-here..."; |
89 | | - # Generate with: mkpasswd -m yescrypt |
| 83 | + # Ship without a usable password. The configurator assigns the first |
| 84 | + # real SSH password, and an optional authorized_keys file on the |
| 85 | + # firmware partition can enable headless key-based access before setup. |
| 86 | + hashedPassword = "$y$j9T$rJ6NmGZ7zE0U4N2hW0g2P.$e6TQ5QliNd3I.M0A2Y2vG7tUc1IQQ6pwT0nMY5myoN5"; |
90 | 87 | }; |
91 | 88 |
|
92 | 89 | security.sudo.wheelNeedsPassword = true; |
|
98 | 95 | (pkgs.callPackage ./reset-configurator.nix { }) |
99 | 96 | ]; |
100 | 97 |
|
| 98 | + systemd.services.lnbitsbox-firstboot-authorized-keys = { |
| 99 | + description = "Import optional first-boot SSH authorized_keys"; |
| 100 | + wantedBy = [ "multi-user.target" ]; |
| 101 | + before = [ "sshd.service" ]; |
| 102 | + after = [ "local-fs.target" "users.target" ]; |
| 103 | + unitConfig = { |
| 104 | + ConditionPathExists = "!/var/lib/lnbits/.configured"; |
| 105 | + }; |
| 106 | + serviceConfig = { |
| 107 | + Type = "oneshot"; |
| 108 | + RemainAfterExit = true; |
| 109 | + }; |
| 110 | + path = with pkgs; [ coreutils gnused shadow ]; |
| 111 | + script = '' |
| 112 | + KEY_SOURCE="/boot/firmware/authorized_keys" |
| 113 | + TARGET_HOME="/home/lnbitsadmin" |
| 114 | + TARGET_DIR="$TARGET_HOME/.ssh" |
| 115 | + TARGET_FILE="$TARGET_DIR/authorized_keys" |
| 116 | +
|
| 117 | + if [ ! -s "$KEY_SOURCE" ]; then |
| 118 | + echo "No first-boot authorized_keys file found." |
| 119 | + exit 0 |
| 120 | + fi |
| 121 | +
|
| 122 | + if [ -e "$TARGET_FILE" ]; then |
| 123 | + echo "authorized_keys already exists for lnbitsadmin, skipping import." |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | +
|
| 127 | + USER_GROUP="$(id -gn lnbitsadmin)" |
| 128 | +
|
| 129 | + install -d -m 0700 -o lnbitsadmin -g "$USER_GROUP" "$TARGET_DIR" |
| 130 | + sed '/^[[:space:]]*$/d; s/\r$//' "$KEY_SOURCE" > "$TARGET_FILE" |
| 131 | + chown lnbitsadmin:"$USER_GROUP" "$TARGET_FILE" |
| 132 | + chmod 0600 "$TARGET_FILE" |
| 133 | +
|
| 134 | + echo "Imported SSH authorized_keys for lnbitsadmin from firmware partition." |
| 135 | + ''; |
| 136 | + }; |
| 137 | + |
101 | 138 | # Display first-boot instructions on login |
102 | 139 | environment.etc."motd".text = '' |
103 | 140 | ╔═══════════════════════════════════════════════════════════╗ |
|
112 | 149 | • Setting your SSH password |
113 | 150 | • Launching LNbits |
114 | 151 |
|
| 152 | + Optional headless SSH before setup: |
| 153 | + • Put your public keys in /boot/firmware/authorized_keys |
| 154 | + • Sign in as lnbitsadmin using key-based auth |
| 155 | + • There is no default SSH password on the image |
| 156 | +
|
115 | 157 | Already configured? LNbits is available at the same URL. |
116 | 158 |
|
117 | 159 | To find this device's IP address, run: ip addr show |
|
0 commit comments