dotfiles/server-quickstart.md
DannyDannyDanny b3c1b04c72 Add NixOS server quick-start guide
Made-with: Cursor
2026-02-27 22:35:43 +01:00

1.4 KiB

NixOS server quick-start

Get a new NixOS machine online as a server: hostname, user, SSH, and key-based login.

1. Prerequisites

  • NixOS installed
  • Machine on the network
  • Console or existing SSH access

2. Hostname

In your config (e.g. /etc/nixos/configuration.nix or a flake module):

networking.hostName = "myserver";

3. User

Define a user in users.users (e.g. danny or admin). For key-only login you can leave the password empty or set a hashed one.

users.users.danny = {
  isNormalUser = true;
  extraGroups = [ "wheel" "networkmanager" ];
  # Optional: hashed password, or omit for key-only login
  # hashedPassword = "...";  # mkpasswd -m sha-512
};

4. SSH

Enable OpenSSH and add your public keys so you can log in without a password.

services.openssh.enable = true;

users.users.danny.openssh.authorizedKeys.keys = [
  "ssh-ed25519 AAAA... your-key-comment"
  # Add more keys (e.g. from ~/.ssh/id_*.pub on your client)
];

Optional hardening (disable password auth, restrict root):

services.openssh.settings = {
  PasswordAuthentication = false;
  PermitRootLogin = "no";
};

5. Apply and test

Rebuild and switch:

sudo nixos-rebuild switch

If you use a flake:

sudo nixos-rebuild switch --flake /path/to/dotfiles/nixos#hostname

From your main machine, test:

ssh danny@myserver

Replace danny and myserver with your user and hostname.