    def add_system_user(self, user):
        """Create a new local UNIX user on the system.

        Tested to work on FreeBSD and Linux, at least.
        """
        name = user.name
        cmd = [arg.replace('USERNAME', name) for arg in self.add_user_cmd]
        try:
            uid = self.uids[name]
            cmd += ['--uid', str(uid)]
        except KeyError:
            self.log.debug(f"No UID for user {name}")
        cmd += [name]
        self.log.info("Creating user: %s", ' '.join(map(shlex.quote, cmd)))
        p = Popen(cmd, stdout=PIPE, stderr=STDOUT)
        p.wait()
        if p.returncode:
            err = p.stdout.read().decode('utf8', 'replace')
            raise RuntimeError(f"Failed to create system user {name}: {err}")
Create a new local UNIX user on the system.

Tested to work on FreeBSD and Linux, at least.
jupyterhub/auth.py