Skip to content

scootgreet login

scootgreet login logs one user in through greetd and starts their session, answering every PAM prompt from input instead of a keyboard. Use it to bring up a VM or a test machine to a logged-in desktop from a script.

greetd runs its greeter as the greeter user with GREETD_SOCK set, and only that process can drive a login. So scootgreet login goes in greetd’s config as the greeter command, with the answers in a file only the greeter user can read:

Terminal window
printf '%s\n' 'the-password' | sudo install -m 600 -o greeter -g greeter /dev/stdin /etc/greetd/answers
/etc/greetd/config.toml
[terminal]
vt = 1
[default_session]
command = "scootgreet login --user alice < /etc/greetd/answers"
user = "greeter"

greetd runs the command with /bin/sh -c "exec <command>", so < and 3< redirections work. Restart greetd to apply it. Delete the answers file once the machine is up: anyone who can read it can log in as that user.

When greetd starts, scootgreet logs alice in and exits, and greetd starts the session. When the session ends, greetd starts its greeter again, which logs in again. To log in only once, use a wrapper script that runs scootgreet login the first time and greetd’s own agreety after that.

Terminal window
scootgreet login --user USER [--session NAME] [--answers-fd N] [--max-attempts N]
scootgreet --help
scootgreet --version
Flag Type Default Meaning
--user USER string required The account to log in.
--session NAME desktop-file id scoot The session to start: wayland-sessions/NAME.desktop, below.
--answers-fd N file descriptor, 3 or more stdin Read answers from inherited descriptor N instead of stdin: a pipe, a socket or a file, e.g. --answers-fd 3 3< answers.
--max-attempts N 1 to 100 3 Give up after N refused attempts.

A value can be attached (--user=alice) or follow the flag. Anything else, including an argument that is not UTF-8, is a usage error, exit 2.

  • One answer per line, in the order PAM asks. A password-then-OTP login needs two lines.
  • Give at least one line, even for an account PAM accepts without a prompt: an input with no answer at all (an empty file, /dev/null) is refused with exit 2 before greetd is asked to open an attempt.
  • visible and secret prompts both take the next line. info and error messages take none; scootgreet prints them and goes on.
  • A line ends at a newline; one \r before it is dropped too. The last line needs no newline. Spaces are kept.
  • An answer is at most 1024 bytes of UTF-8, with no NUL byte. An answer that breaks this cancels the login with exit 2 and names the line number, never the answer: greetd would cut an answer at a NUL, so pw followed by a NUL and more would be checked as pw.
  • Answers come from a pipe, a socket or a file. A terminal is refused, because nothing would hide a password as it is typed: log in by hand with agreety instead.
  • --answers-fd reads the descriptor it is given, from where it stands: a file the parent has partly read continues at its offset, and a file only root can open works when a privileged parent opens it and passes the descriptor. The descriptor must be open and readable: 0, 1 and 2 (for stdin, leave out --answers-fd), an O_PATH descriptor, a write-only one and a directory are refused with exit 2, before greetd is contacted.
  • Answers are never taken on the command line, which every local user can read in /proc/PID/cmdline. A flag like --password is refused, and a stray word after the flags is refused without being echoed.

When greetd refuses a login, scootgreet prints login incorrect; waiting N s and waits. The wait is 1 s after the first refusal, then 2, 4, 8 and 16 s, and stays at 16 s. It resets only after a successful login. After the wait, scootgreet starts a new attempt with the next lines of input, unless:

  • the input has no answer left (end of a file, or a pipe or socket whose writer has closed with nothing unread);
  • PAM refused the attempt without asking anything, as pam_deny, a requisite pam_succeed_if or pam_nologin, or a pam_faillock lockout checked before the password does: another attempt would be refused the same way;
  • --max-attempts attempts were made.

Then it prints login failed; no further attempt and exits 1 (2 when the next answer was unusable).

An attempt abandoned at a prompt counts as a PAM failure, to pam_faillock like a wrong password. So before each attempt scootgreet reads the next answer ahead and checks it, whenever that needs no waiting: from a file, or from a pipe or socket that already holds unread bytes. An input with no answer, or an unusable first answer (too long, not UTF-8, a NUL byte), ends the run with exit 2 before greetd is asked to open an attempt. These cases still cost one abandoned attempt:

  • a writer that keeps a pipe or socket open with nothing in it, then closes it: scootgreet cannot tell the answers ran out, opens the attempt, finds no answer at the prompt, and cancels (exit 1);
  • an answer after the first in one attempt (an OTP after the password) that turns out unusable at its prompt;
  • the input failing to read once the attempt is open, such as a socket reset by its peer.

Write all answers before scootgreet starts, or from a file, to avoid the first two. An answer that arrives late is not one of them: scootgreet waits at the prompt for the next line, also on a pipe or socket the parent left non-blocking (O_NONBLOCK), and leaves that flag as it found it.

The message and the wait are the same for every refusal, the last one included: a wrong password, an unknown user, or a locked account. scootgreet does not print greetd’s reason, which names PAM’s return code and can differ between an account that exists and one that does not. Whether PAM asks for a password at all before refusing is PAM’s choice, and shows in the prompt lines.

PAM’s lockout messages are not shown either. scootgreet recognizes the wording of pam_faillock and pam_tally2 in the C locale (greetd never sets a locale, so PAM modules speak English). Another module’s lockout text, such as pam_sss or an LDAP module, would still be shown. PAM’s own limits (pam_faillock) apply on top of scootgreet’s wait.

Mind pam_faillock’s deny. Every refused attempt is one failure to pam_faillock, so with deny = N one run of --max-attempts N (or more) with wrong answers locks the account. With the default of 3 and a common deny = 3, that is one run. Scripts should pass --max-attempts below the system’s deny, usually --max-attempts 1.

--session NAME starts the session described by wayland-sessions/NAME.desktop, in the first directory of $XDG_DATA_DIRS that has one (default /usr/local/share:/usr/share). The default, scoot, is the entry scoot’s packages install. To use another directory, set the variable in the command:

[default_session]
command = "env XDG_DATA_DIRS=/opt/sessions scootgreet login --user alice --session test < /etc/greetd/answers"
user = "greeter"

On NixOS, session entries are not under /usr/share. They are in services.displayManager.sessionData.desktops, and NixOS puts that directory’s share on the greeter’s XDG_DATA_DIRS whenever a session package is installed. scoot’s entry is installed by programs.scoot.session.enable (default off), which programs.scoot.desktop.enable and programs.scoot.greeter.enable turn on. With it on, --session scoot finds the entry with no setting. If your greeter’s environment lacks it, name the directory in the command:

configuration.nix
services.greetd.settings.default_session.command =
"env XDG_DATA_DIRS=${config.services.displayManager.sessionData.desktops}/share "
+ "scootgreet login --user alice < /etc/greetd/answers";

scootgreet reads the entry’s Exec, DesktopNames and Hidden keys. The session starts with XDG_SESSION_TYPE=wayland, XDG_SESSION_DESKTOP (the first of DesktopNames, else NAME) and XDG_CURRENT_DESKTOP (DesktopNames joined with :, else NAME). %% in Exec is a literal %; an entry whose Exec uses a field code such as %f is refused.

Status Meaning
0 greetd accepted the session; it starts when scootgreet exits.
1 The login failed: refused with no further attempt, the input ran out at a prompt, greetd reported an error, or the connection broke before the session was requested. Nothing was started.
2 A usage or setup error, an answer source with no answer or one scootgreet cannot read, or an unusable answer (too long, not UTF-8, a NUL byte). Nothing was started.
3 The connection broke after scootgreet asked greetd to start the session. greetd may or may not start it: check for the session.

Everything goes to stderr, one line per write, prefixed scootgreet:: each prompt’s text (never the answer), PAM’s info and error messages, each refusal, and the reason for a failure. In PAM’s text, control characters, the Unicode bidirectional controls and marks (U+202A to U+202E, U+2066 to U+2069, U+200E, U+200F, U+061C), the line and paragraph separators (U+2028, U+2029) and the zero-width characters (U+200B to U+200D, U+2060, U+FEFF) are dropped, and long messages are cut at 512 bytes.

  • No session without a full login. scootgreet asks greetd to start the session only after the last prompt is answered correctly. If scootgreet is killed at any point before that, no session starts. If the connection breaks after it has asked, greetd may or may not start the session (exit 3).
  • No stale login left behind. scootgreet cancels before every new attempt and after every error, and reconnects to cancel if the connection breaks mid-login. greetd 0.10.3 keeps an abandoned login until something cancels it, which would otherwise block the next one.
  • Answers stay out of reach. Answers live in buffers that are zeroed after each use and on every error it returns. A panic in a release build aborts the process without zeroing them, and two settings keep them from leaving the process. It is non-dumpable, so other processes of the same user cannot ptrace it or read its memory. Its core file size limit is 0, so a crash writes no core file when core_pattern is a file path or systemd-coredump, including on distributions that set fs.suid_dumpable=2. Another crash handler on a core_pattern pipe (such as apport) receives the memory image and decides for itself. If either setting cannot be applied, scootgreet exits 2 before reading any answer.

Symptom: GREETD_SOCK is not set; run this as greetd's greeter, exit 2.

greetd sets GREETD_SOCK only for its own greeter. Run scootgreet login as greetd’s default_session.command, not from a shell.

Symptom: no such session; looked for …, exit 2.

No wayland-sessions/scoot.desktop in the directories listed. Install scoot’s package, which ships that entry, or point XDG_DATA_DIRS and --session at the entry you want. On NixOS, set programs.scoot.session.enable = true (or programs.scoot.desktop.enable) so the entry is installed; see Sessions.

Symptom: answers come from a pipe, a socket or a file, never a terminal, exit 2.

stdin is a terminal. Redirect the answers from a file, or log in by hand with agreety.

Symptom: --answers-fd 3: Bad file descriptor (os error 9), exit 2.

Descriptor 3 is not open in scootgreet. greetd runs the command with sh -c "exec …", so open it in the same command: --answers-fd 3 3< answers.

Symptom: no answer left for the prompt, exit 1.

There were fewer lines than prompts. Count every prompt PAM asks, OTP included; the prompt lines in the output show which one had no answer.

Symptom: login incorrect, then login failed; no further attempt, exit 1.

The answers are wrong, the user does not exist, or the account is locked or barred by PAM. scootgreet prints the same lines for all of them on purpose. Check the account with sudo faillock --user alice, PAM’s journal lines for greetd, and the answers file’s line order.

Symptom: exit 3, greetd may or may not start the session.

The connection to greetd broke right after scootgreet asked it to start the session. Check whether the session is running before logging in again.