Team Operation Task 1: Create 20 ownCloud Users - KeegMitch/Operations-Engineering-group-c GitHub Wiki

Team Operation Task 1: Create 20 ownCloud Users

Ticket: #895

Resources: https://doc.owncloud.com/server/next/admin_manual/configuration/server/occ_command.html https://doc.owncloud.com/server/next/admin_manual/configuration/server/occ_command.html#creating-users

  • First Issue I've noticed is that in the app server the php version has changed into 8.3 rather than 7.4 which was configured

image

Solution: sudo update-alternatives --config php

Press 1 to change it back to php 7.4

Testing before making a script

This works, gotta find my way around doing this in a script and making the passwords as secure as possible

sudo -u www-data php /var/www/owncloud/occ user:add testuser

image

#!/bin/bash

#generate a secure password
generate_password() {
  tr -dc 'A-Za-z0-9!@#$%^&*()-_=+{}[]<>?~' < /dev/urandom | head -c 16
}

# File to save the usernames and passwords
OUTPUT_FILE="owncloud_users.txt"

#output file is empty before starting
> "$OUTPUT_FILE"

# Loop to create 20 users
for i in $(seq 1 20); do
  USERNAME=$(printf "ocuser%02d" $i)
  PASSWORD=$(generate_password)
  export OC_PASS="$PASSWORD"
  sudo -E -u www-data php /var/www/owncloud/occ user:add --password-from-env --display-name="$USERNAME" "$USERNAME"
  echo "$USERNAME: $PASSWORD" >> "$OUTPUT_FILE"
done

echo "User creation completed. Credentials are saved in $OUTPUT_FILE."

image image

Note: When ownCloud has a user created with a password, the password is automatically hashed using the bcrypt algorithm and stored inside the owncloud database

image