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