Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

411. SSH server

KDOS ships the OpenSSH server, sshd, turned off. Two things keep it from answering the network: a marker file that stops it starting at boot, and the firewall, which drops connections to port 22. This page covers how to turn both on together, the files involved, logging in with keys instead of a password, and why a login is refused.

Installation

openssh, installed by 41_system on every image, provides sshd, the client ssh, scp, sftp, ssh-keygen, ssh-agent and ssh-copy-id. Its build.sh:

./configure --prefix=/usr                     \
			--sysconfdir=/etc/ssh             \
			--libexecdir=/usr/lib/$name       \
			--with-privsep-path=/var/lib/sshd \
			--without-zlib-version-check     \
			--with-security-key-builtin       \
			--with-libedit                    \
			--with-ldns                       \
			--with-xauth=/usr/bin/xauth       \
			--with-kerberos5=/usr
make
make DESTDIR=$PKG install

install -v -m755 contrib/ssh-copy-id $PKG/usr/bin
install -v -m644 contrib/ssh-copy-id.1 $PKG/usr/share/man/man1
install -dm700 -o root -g sys $PKG/var/lib/sshd

install -Dm644 /dev/stdin "$PKG/etc/profile.d/50-ssh-agent.sh" <<'KDOS_SH'
if [ -z "$SSH_AUTH_SOCK" ] && [ -n "$XDG_RUNTIME_DIR" ] && [ -S "$XDG_RUNTIME_DIR/ssh-agent.socket" ]; then
	export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
fi
KDOS_SH

ports/core/servers/openssh/build.sh, lines 12–33

It is built without --with-pam, so sshd checks passwords against /etc/shadow itself and runs no PAM module. --with-security-key-builtin lets it take keys held on a FIDO security key.

The service is sshd, started by /etc/init.d/70_sshd.sh under the supervisor. Whether it starts at boot:

Live medium Installed system
/etc/service.disabled/sshd Present: sshd does not start Present unless the installer’s SSH server choice, or the answer file’s services key, named sshd
Port 22 in the firewall Closed Closed, whatever the installer’s choice
Passwords kdos and root both have the password kdos The ones given to the installer; root is locked unless one was set
Host keys Made when sshd first starts in a session, and kept only in a persistence store Made at the first start on the installed disk. The installer does not copy the live session’s keys

The live column is what a booted live medium does. The installed column is what the installer’s Configure step writes to the new disk; it has not yet been confirmed on a booted installed disk.

mosh works over an SSH login. It is not in the base the ISO carries; sudo kdos update install mosh adds it (see Installing software).

Configuration

/etc/ssh/sshd_config

The server’s configuration is upstream’s file, as make install writes it; no file in the tree replaces it. Every option in it is commented out at its default except AuthorizedKeysFile and the sftp subsystem, which make install points at /usr/lib/openssh/sftp-server. Among the defaults: password logins are accepted, root may log in only with a key (PermitRootLogin prohibit-password), and X11 forwarding is off. Every option is in sshd_config(5).

kpkgadd places every file a package ships, under /etc as everywhere else, so installing openssh again over a root puts upstream’s sshd_config back over an edited one. kpkg check openssh lists an edited file as a config line; see Checking an installed root.

/etc/init.d/70_sshd.sh

From fs/etc/init.d/. It creates the run directory, makes any host key that is missing, and runs sshd in the foreground under the supervisor:

. /etc/init.d/service_helper

NAME="sshd"
DAEMON="/usr/sbin/sshd"

case "$1" in
    start)
        if [ ! -x "$DAEMON" ]; then
            echo "[SKIP] $NAME: $DAEMON not found"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        mkdir -p /run/sshd
        # -A makes each default host key type this OpenSSH knows that is
        # missing and leaves an existing key alone. sshd offers only the types
        # it finds a key file for, so a type left ungenerated is one a client
        # that insists on it cannot connect with.
        ssh-keygen -A
        # -D = don't detach (foreground for supervision). PidFile=none:
        # the supervisor already knows the daemon's pid and keeps its own
        # in /run/kdos-svc.sshd.pid, so a pid file of sshd's is one more
        # file to go stale and nothing reads it.
        supervise "$NAME" "$DAEMON" -D -o PidFile=none
        ;;
    stop)
        stop_service "$NAME"
        ;;
    status)
        check_status "$NAME"
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac

fs/etc/init.d/70_sshd.sh

/etc/service.disabled/sshd

An empty marker, fs/etc/service.disabled/sshd in the tree, that makes rcS skip 70_sshd.sh at boot. It is the one marker the image ships; see the service.disabled reference.

The firewall’s ssh service

kdos-powerd treats ssh as both a port and a daemon. The comment above the code that does it, from src/daemons/kdos-powerd/main.c:

/*
 * `ssh` IS A DAEMON AS WELL AS A PORT. sshd ships disabled — the marker
 * /etc/service.disabled/sshd is in the image — because the live accounts have
 * known passwords, and opening port 22 is how the desktop turns it on. On
 * takes the marker away and starts sshd; off puts the marker back and stops
 * it, so a closed port never hides a listening daemon that one more toggle,
 * or a hand-written rule beside this file, would expose. The marker is what
 * the next boot obeys; the start and stop are this boot.
 */

src/daemons/kdos-powerd/main.c, lines 485–493

The rule it writes goes into /etc/nftables.d/50-kdos-services.nft; see Firewall.

The privilege-separation account

sshd drops to the sshd account for the work it does before a login, with /var/lib/sshd as its empty directory. The account comes from fs/etc/passwd:

sshd:x:996:996:sshd:/var/lib/sshd:/sbin/nologin

fs/etc/passwd, lines 4–4

/etc/profile.d/50-ssh-agent.sh

Written by the openssh build.sh (above). It exports SSH_AUTH_SOCK to $XDG_RUNTIME_DIR/ssh-agent.socket once that socket exists, and starts nothing. The agent is the ssh-agent user service, which runs from the account’s first login to its last logout, shared by every login; see the user’s services:

. /etc/init.d/service_helper

# THE ACCOUNT'S ONE ssh-agent, AT $XDG_RUNTIME_DIR/ssh-agent.socket, from the
# user's first login to the last logout. Every login and everything the
# desktop starts shares it, so `ssh-add` asks for a passphrase once.
# /etc/profile.d/50-ssh-agent.sh, from openssh, exports SSH_AUTH_SOCK to that
# path once the socket exists and starts nothing itself: an agent forked from
# a login shell belongs to no supervisor, outlives the runtime directory
# turnstile removes at the last logout, and the next login starts another
# beside it.
#
# READY WAITS FOR THE SOCKET. The backend holds the login until it reports,
# so the login shell's profile finds the socket and exports the variable.
#
# A STALE SOCKET IS REMOVED ONLY WHILE NO AGENT IS SUPERVISED. ssh-agent
# refuses to bind over an existing path, and one left by an agent that was
# killed would otherwise stop every restart; a running agent's socket is
# left alone, and `supervise` then starts nothing.
#
# --stop-grace 1: ssh-agent exits on SIGTERM at once, and the backend's whole
# stop has to fit turnstile's sixty seconds (40_boxes.sh counts it).

NAME="ssh-agent"
DAEMON="/usr/bin/ssh-agent"
SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"

case "$1" in
    start)
        if [ ! -x "$DAEMON" ]; then
            echo "[SKIP] $NAME: $DAEMON not found"
            exit 0
        fi
        if [ -z "$XDG_RUNTIME_DIR" ] || [ ! -d "$XDG_RUNTIME_DIR" ]; then
            echo "[FAIL] $NAME: no runtime directory; turnstile makes it at the first login"
            exit 1
        fi
        check_status "$NAME" >/dev/null 2>&1 || rm -f "$SOCK"
        echo "[KDOS] Starting $NAME..."
        # -D keeps it in the foreground for supervision.
        supervise --stop-grace 1 "$NAME" "$DAEMON" -D -a "$SOCK"
        ;;
    stop)
        stop_service "$NAME"
        ;;
    status)
        check_status "$NAME"
        ;;
    ready)
        # 0 once the socket exists, 75 while it does not yet; 0 as well when
        # there is no supervised agent to wait for.
        check_status "$NAME" >/dev/null 2>&1 || exit 0
        [ -S "$SOCK" ] || exit 75
        ;;
    *)
        echo "Usage: $0 {start|stop|status|ready}"
        exit 1
        ;;
esac

fs/etc/kdos/user-services/15_ssh-agent.sh

Usage

Turning the server on

Needs membership of wheel.

  1. On the live medium, change both known passwords first, since anyone on the network who reaches port 22 can otherwise log in:

    passwd
    sudo passwd root
  2. Open the port and start the server, in one step:

    kdos-power firewall ssh on

    or switch the ssh row on System Settings → Firewall. Either removes /etc/service.disabled/sshd, starts sshd, and opens TCP 22.

  3. Check:

    service status sshd
    kdos-power firewall list

    service status sshd answers [ OK ] sshd (pid N), and the ssh row reads on.

  4. From another machine: ssh kdos@<address>. The first connection shows the host key’s fingerprint. Compare it with the fingerprint the KDOS machine itself prints for ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub, a line of the form 256 SHA256:<hash> root@<hostname> (ED25519), before answering yes.

The first start makes an RSA, an ECDSA, an Ed25519 and an ML-DSA-44/Ed25519 host key in /etc/ssh/.

An installed system whose installer was asked for the SSH server starts sshd at boot and still drops port 22, so step 2 is needed there too.

Turning it off

kdos-power firewall ssh off

It closes the port, stops sshd and puts the marker back, so the server stays off at the next boot. sudo service stop sshd alone stops it for this boot only.

Logging in with a key

  1. On the client, make a key if you have none:

    ssh-keygen -t ed25519

    or ssh-keygen -t ed25519-sk for one held on a security key; see Fingerprints, FIDO keys and smart cards.

  2. Copy its public half to the KDOS machine:

    ssh-copy-id kdos@<address>

    It appends the key to ~/.ssh/authorized_keys on the server.

  3. Log in with ssh kdos@<address>; no password is asked. /var/log/auth.log on the server, which only root can read (sudo tail /var/log/auth.log), records it as Accepted publickey for kdos from <address> port <n> ssh2: ED25519 SHA256:<hash>.

Refusing password logins

Do this only after a key login works, from a second connection kept open while you change it.

  1. As root, edit /etc/ssh/sshd_config and set:

    PasswordAuthentication no
    KbdInteractiveAuthentication no
  2. Check the file:

    sudo sshd -t

    No output means it is valid.

  3. Restart the server: sudo service restart sshd.

  4. Keep a copy of the edited file. Installing openssh again replaces it with upstream’s, which accepts passwords again.

mosh

  1. Open both services:

    kdos-power firewall ssh on
    kdos-power firewall mosh on

    mosh opens UDP 60000–61000.

  2. From the client: mosh kdos@<address>. It logs in over SSH, then starts mosh-server and continues over UDP.

Tips

Troubleshooting

Connection timed out from the client. The firewall drops port 22. Run kdos-power firewall list and turn ssh on.

Connection refused. The port is open and nothing listens on it. Run service status sshd, then read the service’s logs:

cat /run/kdos-init.sshd.log      # what 70_sshd.sh printed at boot
sudo cat /run/kdos-svc.sshd.log  # the supervisor and sshd's own output; root only

The first exists only when sshd was started at boot; a service start or a firewall toggle prints to the caller instead. The second starts [KDOS] (sshd) Starting: /usr/sbin/sshd.

[SKIP] sshd: /usr/sbin/sshd not found means openssh is not installed. A config error shows as sshd exiting at once and the supervisor restarting it every five seconds; sudo sshd -t names the line.

The server is not started at boot. ls /etc/service.disabled/ lists sshd. Remove it with sudo service enable sshd, or with kdos-power firewall ssh on, which also opens the port.

Permission denied with the right password. Read /var/log/auth.log, where sshd logs every attempt. Only root can read it, so use sudo tail /var/log/auth.log. Root is refused a password login by PermitRootLogin prohibit-password; log in as your own account and use sudo. An account whose shadow entry is locked has no password to give.

A key is refused and the password is asked for. sshd ignores authorized_keys that others can write, and logs Authentication refused: bad ownership or modes for file /home/<user>/.ssh/authorized_keys to /var/log/auth.log, which needs sudo to read. On the server: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys, and make sure the home directory is not group- or world-writable.

The client warns that the host key has changed, on the live medium. Without a persistence store, every boot of the live medium makes new host keys. Remove the old entry on the client with ssh-keygen -R <address>.

sudo over SSH pauses before it asks for the password. The account has a finger enrolled, and pam_fprintd waits on the machine’s reader first; see Fingerprints, FIDO keys and smart cards.

Known gaps

See also