Pre-populate Home Storage for User that hasn't logged in yet

Hi guys,

just deployed an NC11 on CentOS7 connected to an LDAP backend. Usually the home storage folder of a user is created automatically upon first login (/var/www/html/data/${USERID}). Unfortunately I have to migrate some files to a handful of user accounts which haven’t logged in yet.

I wasn’t able to find a way to trigger the creation of the home storage using the console so I am wondering if there is another way to pre-populate the home storage folder of a user in manually?

Thanks in advance!

You may distribute a set of default files and folders to all users by placing them in the nextcloud/core/skeleton directory on your Nextcloud server. These files appear only to new users after their initial login, and existing users will not see files that are added to this directory after their first login. The files in the skeleton directory are copied into the users’ data directories, so they may change and delete the files without affecting the originals.

The configuration option skeletondirectory available in your config.php (See Config.php Parameters) allows you to configure the directory where the skeleton files are located. These files will be copied to the data directory of new users. Leave empty to not copy any skeleton files.

https://docs.nextcloud.com/server/11/admin_manual/configuration_files/default_files_configuration.html?highlight=skeleton

Hi Soko,

thanks for your time. Yes, I am very well aware of the skeleton mechanism but unfortunately that doesn’t answer my question :slight_smile:. The data I need to copy over to the installation is personalized on a per user basis so the skeleton function won’t help.

What I’d like to know is if there’s a way to actually trigger the creation of a user’s home storage folder (and respective database entries) without having the user log in first. All LDAP users were synced and are visible but the home storage folders under /var/www/html/data/${USERID} are still missing. I need to create the home storage folder for all users including required sub folders and database entries prior to the user’s initial login.

I hope you can follow me.

Thanks

Sorry, I don’t know such a mechanism, but did you try to create the userfolders and the content by a script and after that do a filescan with occ for the user?.
That could work…

Yup, in fact I did. But there seems to be something missing as I am always getting an error saying “home storage not writable”. I need to dig a little further and check the source to see what’s being triggered to create the folder and perhaps database entries that I’m missing. Thanks in advance.

@rullzer @nickvergessen @tflidd & @MorrisJobke do any of you know of an OCC command to initialise a user?

I haven’t seen anything in the documentation, so I would guess you have to work around it (or put a feature request and wait for someone to implement it). My first guess was like @Soko said, to populate the content in the future user folder. I’m not sure how Nextcloud reacts if the user folder already exists (make sure the permissions are correct so that the webserver user has full access).

Other idea is to temper somehow with your LDAP (default password) and write a script to login with every user. Or run a script via cronjob that detects newly created users and then copies the files. There is also the first login screen, which you could misuse for this purpose (set a flag in the database).

However, what should be possible is to use external storage by default (also as home directory). In ownCloud this is a enterprise feature but I don’t know if this has been implemented yet (and I have not idea of an ETA).

Log in as this user. We don’t have a command for this.

That’s a shame.

Open a ticket on GitHub with a use case and we can have a look. :wink:

1 Like

No one to help with this functionality??

Have you opened a ticket on GH?

Are there some news yet? Because i have to trigger the first login of a new user too.

I have the same issue. I need to pre-populate a user directory with personal files from another system before they log for the first time.
I’m looking if an issue is open on github.

I had this same problem with users added via the Raw SQL User Backend app on Nextcloud 16, but discovered (after some experimentation) that I could pre-create the “/files/” directories in the Nextcloud data directory, put the necessary files therein, make sure they had the correct permissions, and it would Just Work - on initial login, the user would see the initial login wizard, skeleton files would be copied over, and the files I’d pre-copied would be there as well.

No idea if this applies to users added via any other method (native nextcloud, LDAP, whatever), but it worked for me, so those of y’all with this issue might try experimenting with that approach with a test username.

+1 for me. I have the same problem.

First login can be simulated by script, I don’t know if this would pre-populate with the skeleton for remote users such as LDAP, but it works for me on NextCloud 28.

#!/usr/bin/env python
# vim: set et sw=4 sts=4 ts=4:
"""
connect_as_user.py USERNAME [<user_password>]

password can also be read from env var OC_PASS
"""
import requests
import os
import sys

# set your nextcloud own URL
nc_url = "https://your.nextcloud.url"

# get username from command line first argument
username = sys.argv[1]

# pasword can be given from env var or command line
if len(sys.argv) > 2:
    user_password = sys.argv[2]
else:
    user_password = os.getenv('OC_PASS')

if user_password is None or len(user_password) == 0:
    print("user_password is empty")
    exit(1)

# prepate API call
headers = {"OCS-APIRequest": "true"}

# connecting as new user will populate the files folder with template
auth = (username, user_password)
r = requests.get(f"{nc_url}/ocs/v2.php/cloud/user", auth=auth, headers=headers)

if r.status_code == 200:
    print(f"Connected as {username}, the Nextcloud account is completed")
else:
    print(f"Connection error : {r.text}")

works on my user created from command line with occ user:add

hope that could help someone else.

https://cloud-py-api.github.io/nc_py_api/Installation.html