Configure Quota from CLI?

Hello,

Iā€™m not sure if i chose the correct catagory for tis question, but I will try here anyway.

Iā€™m trying to learn to configure the Nextcloud within the CLI of Ubuntu 20.04 and Iā€™m trying to create an users and groups.

Iā€™m able to create the users and groups fineā€¦ But I canā€™t find if I somehow can add the quota for users? Can I only change the qouta for users within the webgui?

Commands used:

sudo -u www-data php occ user:add --display-name=ā€œTest User2ā€
ā€“group=ā€œtestingā€
testuser2

sudo -u www-data php occ user:add --display-name=ā€œTest User3ā€
ā€“group=ā€œtestingā€
ā€“quota=ā€œ1073741824ā€ \ <---- Will give an error
testuser3

How can i set a quota for new users in the CLI? And where can I see all the quota settings? Canā€™t see anything within the occ command page (Using the occ command ā€” Nextcloud latest Administration Manual latest documentation) or in the database.

Please help. :slight_smile:

It is not the right answer to your question, but the User provisioning API could also be an alternative if you want to do a bigger thing.
https://docs.nextcloud.com/server/19/admin_manual/configuration_user/instruction_set_for_users.html#add-a-new-user

POST argument: quota - string, quota for the new user

I think your use-case should work. If not it is not well documented or not implemented. ā†’ Feature-Request?

Thanks! I will try it out and check if I can do what I need to do with it,

But I also moved my ticket to the feature forum (Didnā€™t see any feature-request one?)

Humā€¦ It seems that it doesnā€™t workā€¦ Iā€™m only getting {ā€œmessageā€:ā€œCSRF check failedā€}

curl -k -X POST ā€˜https://admin:Admin!23@our-domain.com/ocs/v1.php/cloud/usersā€™ -d userid=ā€˜Testuser2ā€™ -d password=ā€˜Testing!ā€™
{ā€œmessageā€:ā€œCSRF check failedā€}

Any ideas?

Oh, I got the same issue. After a little research I found this solution.

add -H "OCS-APIRequest: true"

curl -X POST https://admin:password@cloud.example.com/ocs/v1.php/cloud/users -H "OCS-APIRequest: true" -d userid="Frank" -d password="FranksPassword"
<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>100</statuscode>
  <message>OK</message>
  <totalitems></totalitems>
  <itemsperpage></itemsperpage>
 </meta>
 <data>
  <id>Frank</id>
 </data>
</ocs>

That seems to workā€¦ but I get another issue thenā€¦

bahnhof@ubuntu:~$ curl -X POST https://admin:Admin!23@cloud.example.com/ocs/v1.php/cloud/users -H "OCS-APIRequest: true" -d userid="Frank" -d password="FranksPassword"
-bash: !23: event not found

If i have a password with ! n it it wont work, but when I changed it with just letters it workedā€¦ any idea?

Owā€¦ I even had to use -k to remove a SSL error:

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Soā€¦

curl -k -X POST https://admin:Admin!23@cloud.example.com/ocs/v1.php/cloud/users -d userid="Testuser2" -d password="Testing!"

does not work but this will work:

curl -k -X POST https://admin:testingwiththispw@cloud.example.com/ocs/v1.php/cloud/users -d userid="Testuser2" -d password="Testing!"

Any idea why?

try to escape the ! with \ so it will be Admin\!23, so it will be interpreted as a letter and not an operator.

Ahh that might workā€¦
I told this fix for my colleague and showed him that we canā€™t use the occ command and need to use CURL for quotaā€¦ he found that occ an be usedā€¦

It is in user:settingā€¦

sudo -u www-data php occ user:setting [uid] files quota 1073741824
OR
sudo -u www-data php occ user:setting [uid] files quota 1GB

I have been looking at user:setting, but couldnā€™t find itā€¦ but it seems like it works.

So for the solution:

sudo -u www-data php occ user:add --display-name="Layla Smith"
  --group="users" --group="db-admins" layla
sudo -u www-data php occ user:setting layla files quota 1GB

Will create a user named lala with display name of Layla smith and add it to the users and db-admins groups then change the quota to 1GB.

3 Likes