NextCloud: Create User via CLI

As the NextCloud WebUI had a bug and didn't let me create new users I needed to find an alternative way to do so.
After some digging I found the following method to work and have been using it since:

Substitute[1]the 'www-data' user:
sudo su -s /bin/sh www-data
As this user, export the password for the new user to the 'OC_PASS' variable:
export OC_PASS=<pass>
Call the NextCloud/ownCloud command line tool 'occ' and create the user:
php /var/www/nextcloud/occ user:add --password-from-env --display-name="<username>" --group="users" <username>
Finally, stop substituting by typing: exit.

You should now see the newly created user in the NextCloud/ownCloud web interface.

  1. ↩︎