--- title: Create an admin user params: host: { type: host, required: true, label: Target server } user: { type: name, required: true, label: User name } pubkey: { type: string, required: true, label: Public SSH key } shell: { type: path, default: /bin/bash, label: Login shell } --- # Create an admin user A guided runbook: each section asks for what it needs where it is explained. A section's outline turns green once its values are filled in. For Debian hosts; runs need passwordless sudo and ask for confirmation. :::group{title="1. Pick the server"} Choose the machine from Hosts. This check only reads state. ::param{name=host} ```sh {check host="{{host}}" id=can-sudo title="Passwordless sudo works" sudo} true ``` ::: :::group{title="2. Describe the user"} Pick a login name (letters, digits, `.`, `_`, `-`) and paste the public key the user logs in with, e.g. the content of their `~/.ssh/id_ed25519.pub`. ::param{name=user} ::param{name=pubkey} ::param{name=shell} ```sh {check host="{{host}}" id=user-free title="User does not exist yet"} ! id {{user}} ``` ::: :::group{title="3. Create the user"} Creates **{{user}}** in the `sudo` group and authorizes the key. ```sh {run host="{{host}}" id=create title="Create user and authorize key" sudo confirm} useradd --create-home --shell {{shell}} --groups sudo {{user}} install -d -m 700 -o {{user}} -g {{user}} /home/{{user}}/.ssh printf '%s\n' {{pubkey}} > /home/{{user}}/.ssh/authorized_keys chown {{user}}:{{user}} /home/{{user}}/.ssh/authorized_keys chmod 600 /home/{{user}}/.ssh/authorized_keys ``` ::: :::group{title="4. Verify" collapsed} ```sh {check host="{{host}}" id=verify title="User is in sudo and has the key" sudo} id -nG {{user}} | grep -qw sudo test -s /home/{{user}}/.ssh/authorized_keys ``` :::