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

419. File sharing

This page is for anyone who wants to reach files on other machines, or share files with them. It covers opening a Windows (SMB) share as an ordinary user, mounting and exporting NFS (the Unix network file system), running a Samba server, keeping folders in step with Syncthing, and sending a single file with kdos share. Finding the machines on the network by name is on Avahi and mDNS; the firewall names each server needs are explained in the KDOS book’s Opening a service.

Installation

Every port on this page is on the installation image except syncthing, gvfs and kdenetwork-filesharing (Dolphin’s Share tab), which sudo kdos update install <port> adds (see Installing software).

Task Ports What starts it
Opening an SMB share as a user kio-extras, its smb:/ worker, in Dolphin and every KDE program the program, on use
Mounting an SMB share as root cifs-utils mount -t cifs, by hand
Mounting with a Kerberos ticket krb5, cifs-utils the kernel, through request-key, on the mount
Serving SMB samba, with kdenetwork-filesharing for Dolphin’s Share tab 83_samba, at boot once sambashare has a member or something is shared; the first login of an account just added to sambashare starts it through kded-kdos and kdos-powerd
Mounting and serving NFSv4 nfs-utils 72_nfsd, once /etc/exports names a share; 63_gssd, once /etc/krb5.keytab exists
Syncing folders syncthing File Sync in the application menu, by hand
Sending one file croc, kdos-tools (kdos share) by hand
Shares in GTK file managers gvfs the session bus, on first use

The three server scripts, 72_nfsd, 63_gssd and 83_samba, are installed by their ports and exist only while the port is installed. None of them is among the installer’s service choices. Each one skips itself at boot, with a [SKIP] line, while it has nothing to serve:

Script Starts once Its line while skipped
83_samba some account can share (see below) [SKIP] samba: no account shares folders, in /run/kdos-init.samba.log
72_nfsd /etc/exports names a share [SKIP] nfsd: no share in /etc/exports, in /run/kdos-init.nfsd.log
63_gssd /etc/krb5.keytab exists [SKIP] gssd: no /etc/krb5.keytab, in /run/kdos-init.gssd.log

service status nfsd names the daemon it watches, nfsv4.exportd.

The servers behave the same on the live medium and on an installed system; what differs is where the configuration lives. On the live medium /etc is in memory and is lost at power-off unless a persistence store exists (kdos persist); on an installed system it is on the root filesystem.

Configuration

/etc/request-key.d/cifs.spnego.conf

A Kerberos mount needs the kernel to ask cifs.upcall for a ticket. The krb5 port installs the rule that joins them:

install -Dm644 /dev/stdin "$PKG/etc/request-key.d/cifs.spnego.conf" <<'RK'
create cifs.spnego * * /usr/sbin/cifs.upcall %k
RK

ports/core/auth/krb5/build.sh, lines 60–62

/etc/samba/smb.conf

The image ships a standalone server whose shares are the users’ own usershares, made from Dolphin’s Share tab, from fs/etc/samba/smb.conf:

#   Samba on KDOS: a standalone file server whose shares are the users'.
#
# A folder is shared from Dolphin's Properties > Share tab, which creates a
# USERSHARE with `net usershare` and reads the settings below through
# `testparm`. A usershare is one file in `usershare path`; smbd picks it up
# with no restart. Without these lines the tab can only say that sharing is
# not set up, and every share fails.
#
# THE DIRECTORY IS THE PERMISSION. `net usershare` writes there as the user,
# so it must be root's, group sambashare, mode 1770: only a member of the
# group can add a share, and the sticky bit stops one member deleting
# another's. The share tab adds its user to the group through an
# administrator prompt. The samba package's service script makes the
# directory at every boot, whether or not smbd then starts: a package cannot
# carry that mode.
#
# smbd runs only once an account can share. /etc/init.d/83_samba.sh starts
# it at boot when the sambashare group has a member, the usershare directory
# holds a share or this file defines one below [global], and skips it
# otherwise. It must be running before the first share is made: `net
# usershare add` asks smbd to turn the names in a share's ACL into SIDs, and
# fails without it. An account the share tab has just added to the group
# starts it at its next login: the session's kded-kdos asks kdos-powerd,
# through polkit, to run that script. Other machines
# reach a share only once the firewall's `smb` service is opened in System
# Settings or with `kdos-power firewall smb on`; until then port 445 is
# closed.
#
# Printers are not shared: CUPS shares its own over IPP, and a Samba printer
# share would offer every local queue to every SMB client. A share defined
# here by hand, below [global], is served as well as the users' shares.
# ---------------------------------

[global]
	workgroup = WORKGROUP
	server role = standalone server
	server string = KDOS
	map to guest = bad user

	usershare path = /var/lib/samba/usershares
	usershare max shares = 100
	usershare allow guests = yes
	usershare owner only = yes

	load printers = no
	printing = bsd
	printcap name = /dev/null
	disable spoolss = yes

fs/etc/samba/smb.conf

The samba port’s service script starts smbd alone: no nmbd and no winbindd. With a non-empty smb.conf, it makes the usershare directory at every boot (owned by root, group sambashare, mode 1770, which a package cannot carry), and then starts smbd only if one of these holds:

Otherwise it prints [SKIP] samba: no account shares folders, and nothing listens on the SMB ports:

install -d "$PKG/etc/init.d"
cat > "$PKG/etc/init.d/83_samba.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper

NAME="samba"
DAEMON="/usr/sbin/smbd"
USERSHARES="/var/lib/samba/usershares"

has_member() {
    grep -Eq '^sambashare:[^:]*:[^:]*:[^:[:space:]]' /etc/group
}

has_shares() {
    for f in "$USERSHARES"/*; do
        case "${f##*/}" in :*) continue ;; esac
        [ -f "$f" ] && [ ! -L "$f" ] && return 0
    done
    grep -Eiv '^[[:space:]]*\[global\]' /etc/samba/smb.conf |
        grep -Eq '^[[:space:]]*\['
}

case "$1" in
    start)
        [ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
        if [ ! -s /etc/samba/smb.conf ]; then
            echo "[SKIP] $NAME: no /etc/samba/smb.conf"
            exit 0
        fi
        install -d -m 755 /var/log/samba /var/cache/samba
        install -d -m 1770 -o root -g sambashare "$USERSHARES"
        if ! has_member && ! has_shares; then
            echo "[SKIP] $NAME: no account shares folders"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        supervise --stop-grace 15 "$NAME" "$DAEMON" --foreground --no-process-group
        ;;
    stop)   stop_service "$NAME" ;;
    status) check_status "$NAME" ;;
    *)      echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/83_samba.sh"

ports/core/servers/samba/build.sh, lines 64–107

smbd has to be running before the first share can be made. net usershare add turns every name in a share’s access list, Dolphin’s Everyone among them, into a Windows security id (SID) by asking the local smbd; with smbd down it fails with “cannot convert name … to a SID” and writes no share.

An account the Share tab has just added to sambashare is a member from its next login, which can come before the next boot. So that the server is running for it:

  1. kded-kdos, loading in a session that can write into the usershare directory, calls StartFileSharing once on kdos-powerd’s io.kdos.Power1 interface.
  2. The daemon asks polkit for io.kdos.filesharing.start, which is granted with no prompt to the person at the machine.
  3. It runs /etc/init.d/83_samba.sh start, which makes the same test again and starts nothing when smbd already runs. It refuses while /etc/service.disabled/samba exists.

Leaving the group or removing the last share leaves smbd running, serving nothing, until the next boot, which then does not start it.

The configure options set where Samba keeps its files: the configuration under /etc/samba, the lock files under /var/lib/samba/lock, the password database under /var/lib/samba/private and the logs under /var/log/samba:

./configure \
	--prefix=/usr \
	--enable-fhs \
	--sysconfdir=/etc \
	--libdir=/usr/lib \
	--localstatedir=/var \
	--with-piddir=/run/samba \
	--with-lockdir=/var/lib/samba/lock \
	--with-privatedir=/var/lib/samba/private \
	--with-logfilebase=/var/log/samba \

ports/core/servers/samba/build.sh, lines 16–25

The lock directory is not Samba’s default /var/lock/samba, which is in the world-writable /run/lock. There, any Samba client run before smbd, net usershare among them, would make the directory as its own user, and smbd would then refuse the msg.lock directory inside, which is not root’s, and exit at every start. /var/lib/samba/lock belongs to the package, owned by root with mode 0755, so a client makes nothing in it and still works.

smbd creates neither /var/log/samba nor /var/cache/samba. Both exist on the live medium and on an installed system, because the package claims them and the image carries every directory a package claims under /var/log and /var/cache, empty (110_iso). The service script also creates both before each start, so emptying /var/log does not cost the server its log. If they are missing, testparm reports ERROR: cache directory /var/cache/samba does not exist, and the server’s log lines go only to the supervisor’s /run/kdos-svc.samba.log, among them Unable to open new log file ‘/var/log/samba/log.smbd’.

/etc/exports and the NFS scripts

nfs-utils installs two service scripts. 72_nfsd is the NFSv4 server; it skips itself until /etc/exports has a line that is not blank or a comment, and starts the kernel server with NFSv3 turned off (-N 3 -V 4):

install -d "$PKG/etc/init.d"
cat > "$PKG/etc/init.d/72_nfsd.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper

NAME="nfsd"
DAEMON="/usr/sbin/rpc.nfsd"
EXPORTFS="/usr/sbin/exportfs"
PIPEFS="/var/lib/nfs/rpc_pipefs"

case "$1" in
    start)
        [ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
        if ! grep -qEv '^[[:space:]]*(#|$)' /etc/exports 2>/dev/null; then
            echo "[SKIP] $NAME: no share in /etc/exports"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        modprobe nfsd 2>/dev/null
        grep -q " /proc/fs/nfsd nfsd " /proc/mounts || \
            mount -t nfsd nfsd /proc/fs/nfsd
        mkdir -p "$PIPEFS" /var/lib/nfs/nfsdcld
        grep -q " $PIPEFS rpc_pipefs " /proc/mounts || \
            mount -t rpc_pipefs sunrpc "$PIPEFS"
        # -F and -f: each stays in the foreground for ksvc.
        supervise nfsdcld /usr/sbin/nfsdcld -F
        "$EXPORTFS" -r
        supervise nfsv4.exportd /usr/sbin/nfsv4.exportd -f
        "$DAEMON" -N 3 -V 4
        ;;
    stop)
        # Threads first, so no request arrives to an export being withdrawn.
        "$DAEMON" 0 2>/dev/null
        "$EXPORTFS" -ua 2>/dev/null
        stop_service nfsv4.exportd
        stop_service nfsdcld
        ;;
    status)
        check_status nfsv4.exportd
        ;;
    *)  echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/72_nfsd.sh"

ports/core/filesystem/nfs-utils/build.sh, lines 42–85

63_gssd is the Kerberos half of an NFS client, for a sec=krb5 mount, and skips itself until /etc/krb5.keytab exists and is not empty:

cat > "$PKG/etc/init.d/63_gssd.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper

NAME="gssd"
DAEMON="/usr/sbin/rpc.gssd"
PIPEFS="/var/lib/nfs/rpc_pipefs"

case "$1" in
    start)
        [ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
        if [ ! -s /etc/krb5.keytab ]; then
            echo "[SKIP] $NAME: no /etc/krb5.keytab"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        # sunrpc registers rpc_pipefs; rpcsec_gss_krb5 is what the kernel
        # asks for when a sec=krb5 mount arrives.
        modprobe sunrpc 2>/dev/null
        modprobe rpcsec_gss_krb5 2>/dev/null
        mkdir -p "$PIPEFS"
        grep -q " $PIPEFS rpc_pipefs " /proc/mounts || \
            mount -t rpc_pipefs sunrpc "$PIPEFS"
        # -f keeps it in the foreground for ksvc.
        supervise "$NAME" "$DAEMON" -f
        ;;
    stop)   stop_service "$NAME" ;;
    status) check_status "$NAME" ;;
    *)      echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/63_gssd.sh"

ports/core/filesystem/nfs-utils/build.sh, lines 87–118

Syncthing’s first configuration

kdos-syncthing, the command behind File Sync, gives a user who has no Syncthing configuration this one, which keeps discovery on the local network and turns off the global announce server, relays, NAT traversal and usage reporting:

install -Dm644 /dev/stdin $PKG/usr/share/kdos/syncthing-offline.xml <<'XML'
<!-- The configuration kdos-syncthing gives a user who has none. These keys
     are what keep a sync between two machines on one LAN from reaching
     anything outside it. -->
<configuration version="52">
    <options>
        <localAnnounceEnabled>true</localAnnounceEnabled>
        <globalAnnounceEnabled>false</globalAnnounceEnabled>
        <relaysEnabled>false</relaysEnabled>
        <natEnabled>false</natEnabled>
        <urAccepted>-1</urAccepted>
        <autoUpgradeIntervalH>0</autoUpgradeIntervalH>
    </options>
</configuration>
XML

ports/core/transfer/syncthing/build.sh, lines 25–39

The wrapper looks for an existing configuration first, and writes the file above only where there is none:

cat > "$PKG/usr/bin/kdos-syncthing" <<'KDOS_SH'
#!/bin/sh
if [ -n "$STHOMEDIR" ]; then
	dir=$STHOMEDIR
elif [ -n "$STCONFDIR" ]; then
	dir=$STCONFDIR
elif [ -n "$XDG_CONFIG_HOME" ] && [ -f "$XDG_CONFIG_HOME/syncthing/config.xml" ]; then
	dir=$XDG_CONFIG_HOME/syncthing
elif [ -f "$HOME/.config/syncthing/config.xml" ]; then
	dir=$HOME/.config/syncthing
else
	case "$XDG_STATE_HOME" in
	/*) dir=$XDG_STATE_HOME/syncthing ;;
	*) dir=$HOME/.local/state/syncthing ;;
	esac
fi
if [ ! -e "$dir/config.xml" ]; then
	mkdir -p "$dir" && chmod 700 "$dir" &&
		install -m600 /usr/share/kdos/syncthing-offline.xml "$dir/config.xml"
fi
exec syncthing serve "$@"
KDOS_SH
chmod 755 "$PKG/usr/bin/kdos-syncthing"

ports/core/transfer/syncthing/build.sh, lines 42–64

croc

kdos share hands the transfer to croc, and /usr/bin/croc is a wrapper that keeps every transfer on the local network. croc-relay is the same program with upstream’s default relay:

install -Dm755 /dev/stdin $PKG/usr/bin/croc <<'SH'
#!/bin/sh
# --local keeps the transfer on this network. `croc-relay` is the same binary
# with upstream's default, for when reaching the public relay is the intent.
exec /usr/bin/croc-relay --local "$@"
SH

ports/core/transfer/croc/build.sh, lines 23–28

Usage

Opening an SMB share from the desktop

  1. In Dolphin, open Network in the Places panel, then Shared Folders (SMB), which lists the file servers that answer mDNS, NetBIOS or WS-Discovery; or type the address in the location bar: smb://fileserver/projects.
  2. Give your account on the server and its password when asked; Remember password keeps it in KWallet.
  3. The share opens as a folder. Add to Places keeps it in the Places panel. Every KDE program opens and saves files there directly; a program that is not KDE’s is given a local copy.

GTK applications reach the same shares through gvfs, as smb://server/share.

Mounting an SMB share from a terminal

As root, mount.cifs mounts a share into the filesystem, for programs that need a real path:

sudo mkdir -p /mnt/share
sudo mount -t cifs //fileserver/projects /mnt/share -o username=you,uid=$(id -u),gid=$(id -g)

With a Kerberos ticket, kinit you@EXAMPLE.ORG first and mount with -o sec=krb5,cruid=$(id -u). Mount on a directory of its own rather than on /mnt: on the live medium /mnt holds the boot medium at /mnt/iso and the persistence store at /mnt/persist, and a mount over /mnt hides both until it is undone.

Mounting an NFS export

  1. Mount it as root, naming version 4, on a directory of its own:

    sudo mkdir -p /mnt/share
    sudo mount -t nfs4 fileserver:/srv/share /mnt/share

    mount.nfs4 returns once the mount is made, and sudo umount /mnt/share undoes it. /etc/mtab is a link to the kernel’s own list, /proc/self/mounts, so the helper keeps no table of its own.

  2. An NFSv3 server needs -o nolock on the client, which keeps file locks on this machine. This has not been tested against an NFSv3 server, because this machine’s own server speaks NFSv4 only:

    sudo mount -t nfs -o vers=3,nolock fileserver:/srv/share /mnt/share
  3. To let an ordinary account mount the export, list it in /etc/fstab with the user option and noauto, so the boot does not try it:

    fileserver:/srv/share  /mnt/share  nfs4  user,noauto  0 0

    The account then runs mount /mnt/share without sudo. Of the fstab lines an ordinary account might mount, only an NFS one works this way: util-linux’s mount is not setuid, but it hands the line to mount.nfs, which is setuid root and checks the user option itself (see setuid binaries and Adding a disk to fstab).

    Unmounting still takes sudo umount /mnt/share: an ordinary account may unmount only a mount recorded as its own, and nothing records it, because /etc/mtab is the kernel’s list and keeps no owner. Neither the mount nor the unmount has been tested on a booted image.

Serving a folder over SMB

Dolphin’s Share tab comes from kdenetwork-filesharing, which is not on the image: install it first with sudo kdos update install kdenetwork-filesharing.

  1. In Dolphin, right-click the folder → Properties → Share.

  2. Tick Share with SMB. The first time, the tab says you are not in sambashare: Make Me a Group Member asks for an administrator’s password. Log out and in again; the tab says to restart the system, but a new login is enough, and that login starts smbd with no prompt.

  3. Back on the tab, Set Samba password asks for an administrator’s password a second time and creates your entry in Samba’s password database, with a password Samba keeps apart from the login password: the one other machines sign in with.

  4. Home folders are mode 0700, so the tab says the folder needs extra permissions: Fix Permissions lets others pass through your home folder (o+x), not list it, so smbd can reach the shared folder.

  5. Choose who may read or write it, and OK. The share is a usershare under /var/lib/samba/usershares, and the running smbd picks it up at once. With smbd down the tab reports that Everyone cannot be converted to a SID, and no share is made.

  6. Open the firewall to other machines:

    kdos-power firewall smb on

    or turn on smb on System Settings → Firewall. smb opens TCP 445 only.

From a terminal, a member of sambashare makes the same share with net usershare add <name> <path> "<comment>" <acl> guest_ok=n while smbd runs. A share defined in smb.conf below [global] is served too. sudo service start samba starts smbd when nothing else has, testparm -s checks the file, and smbclient -L localhost -U <you> lists what is served.

On the live medium, the shares, the group membership and the Samba password under /var/lib/samba/private are all held in memory and are gone at the next reboot, unless the medium has a persistence store (Live persistence).

Serving a folder over NFS

  1. Add the export to /etc/exports, in the form exports(5) describes, for example /srv/share 192.168.1.0/24(rw,sync,no_subtree_check).

  2. Start the server:

    sudo service start nfsd

    If it is already running, sudo exportfs -r applies the edited file instead.

  3. Open the firewall:

    kdos-power firewall nfs on

    nfs opens TCP 2049. The server speaks NFSv4 only, so no portmapper port is needed; cat /proc/fs/nfsd/versions prints -3 +4 +4.1 +4.2 while it runs.

On the live medium the root filesystem is an overlay, which the kernel’s NFS server cannot export, and an NFSv4 client reaches every export through the root. A mount of any export below / fails with mount.nfs4: mounting :/srv/share failed, reason given by server: No such file or directory, whatever filesystem the export is on. Instead, export a filesystem of its own, such as a mounted disk, as the server’s root with fsid=0, and mount it as <server>:/:

sudo mkdir -p /srv/nfs
sudo mount /dev/sdb1 /srv/nfs
echo '/srv/nfs 192.168.1.0/24(rw,sync,no_subtree_check,fsid=0)' | sudo tee /etc/exports
sudo service start nfsd

and on the client, sudo mount -t nfs4 <server>:/ /mnt/share. Mounted from this machine itself, such an export is writable by the account that owns its top directory.

An export below / on an installed system, whose root is a real filesystem, has not been tested.

Syncing a folder with Syncthing

  1. On each machine, open File Sync from the application menu. It runs kdos-syncthing in a terminal and serves the web interface on 127.0.0.1:8384; closing the terminal stops syncing.

  2. On each machine, open the firewall name:

    kdos-power firewall syncthing on

    It opens TCP 22000 and UDP 22000 for syncing and UDP 21027 for discovery.

  3. In the web interface, add the other machine’s device ID and share a folder with it.

Sending one file

  1. Send it:

    kdos share report.pdf

    The window shows a code word, and the same code as a QR code when the window is large enough to hold it whole.

  2. On the other machine, receive it:

    croc <code>

Send with a Code Word in a file’s context menu in Dolphin runs the same command in a terminal of its own. Every option is in kdos share.

Tips

Troubleshooting

Dolphin’s network view lists nothing, or not the machine you want. The list is whatever answered an mDNS query, a NetBIOS broadcast and a WS-Discovery probe at that moment. A machine that is asleep, on another subnet or behind a router that does not forward multicast is missing; type its name or address instead. Check that Avahi runs (service status avahi).

A Kerberos mount fails with Required key not available. The kernel found no ticket. Check klist as the user who asked for the mount, and run kinit again when the ticket has expired. /etc/request-key.d/cifs.spnego.conf and cifs.upcall must both be there.

smbd does not start. Read what its script printed at boot:

cat /run/kdos-init.samba.log

The file holds the boot’s output only; a later sudo service start samba prints on the terminal.

If a member’s login did not start smbd, look in that session’s log: grep io.kdos.kded ~/.local/share/sddm/wayland-session.log shows whether the module asked (it does not in a session that is not yet in sambashare) and what kdos-powerd answered. A refusal also raises a Folder sharing unavailable notification. Otherwise run testparm -s, and read the supervisor’s log, /run/kdos-svc.samba.log, and /var/log/samba/log.smbd.

The Share tab says sharing is not set up, or a share is refused. The usershare directory must be root’s, group sambashare, mode 1770: ls -ld /var/lib/samba/usershares. sudo service restart samba makes it again. Your account must be in sambashare in this session: id.

Another machine cannot reach this one’s share. The firewall drops it. kdos-power firewall list shows which names are on; smb serves SMB and nfs serves NFS.

mount -t nfs4 never returns. The mount is already made: grep nfs /proc/mounts lists it and its files can be used. /etc/mtab is missing, and mount.nfs4 loops trying to update it. Kill it (sudo pkill -x mount.nfs4) and restore the link, sudo ln -s ../proc/self/mounts /etc/mtab, or mount with -n, which tells the helper not to record the mount.

An NFSv3 mount is refused when it asks for locking. There is no rpcbind for rpc.statd to register with. Mount with -o nolock.

Two Syncthing machines do not find each other. Both need the syncthing firewall name on, and both must be on the same network: global discovery and relays are off in the configuration kdos-syncthing writes.

Known gaps

See also