Introduction

Normally, during the installation of FreeBSD, a user can (but does not have to) be created by the installer, which is required for the activation of SSH. If this has not been done, a brief explanation of how to do this is provided here. A newly created jail also has no user other than root by default and requires the same steps.

Access via SSH as root should be avoided for security reasons

A user can be used in two ways, the latter is more suitable to be automated in scripts.

adduser

The command adduser is so far self-explanatory. Since we want to create an administrative user here, it is important that the user belongs to the wheel group. The rest is a matter of taste.

pw

The command pw can be used in scripts. adduser is more or less just a frontend, which is based on pw in the background.

pw user add -n USERNAME -c ‘NAME’ -d /home/USERNAME -G GROUP -m -s /bin/sh`

For example, to create a user with a random password, the following could be used.
In the first step, the password is generated and written to the file USERNAME.passwd, protected by chmod, and then set by pw usermod. Finally, the password is then displayed for further use / documentation.

head -c 10 /dev/random | uuencode -m - | tr -d '\n' | cut -c 19-32 > USERNAME.passwd && chmod 600 USERNAME.passwd
pw usermod USERNAME -h 0 < USERNAME.passwd
cat USERNAME.passwd

Voilá