rset(1) : Formulas

Configuring User Accounts

OpenBSD

Modifying and adding users is straitforward as a one for script that is run once. For particular hosts a case statement can be used to adding users that are not everywhere present.

users:
    usermod -p '$$2b$08$BVK.0pbhzQZB0KDPXI92OOVaJ09s/h8CNv3TbS8caZT0gHsprjvHW'
        root
    case "$(hostname -s)" in
        xps13)
            useradd -u 1006 -G wheel -c "Abigail Radman" abigail
          ;;
        xa10)
            useradd -u 1002 -g 10 -c "AuthPF" -s /usr/sbin/authpf wwwproxy
            useradd -u 1003 -g 10 -c "AuthPF" -s /usr/sbin/authpf unlockwww
            ;;
    esac

Since useradd(8) and usermodify(8) take most of the same arguments we can easily convert this to a script that will add or modify users.

users:
    function userset {
        useradd -m "$@" 2> /dev/null && return
        # knock off parameters that we don't want to change
        if [ $1 == '-u' ]; then
            shift # -u
            shift # uid
        fi
        usermod "$@"
    }

If you also want to display differences can diff the before and after instance of the password file

users:
    function userset {
        cp /etc/passwd /tmp/passwd
        ...
        diff /tmp/passwd /etc/passwd
      rm /tmp/passwd
    }

Last updated on September 12, 2018