Mmctl: create the first user

Hello there,

I’m scripting the deployment of new Mattermost instances (mattermost_ynh/install at master · YunoHost-Apps/mattermost_ynh · GitHub), and I’m trying to create the first user of the server.

So I do

bin/mmctl user create --email $email --username=$admin --password '$password' --locale $language --system-admin

But it fails with:

Error: cannot read user credentials, maybe you need to use login first

The thing is, I can’t authenticate, as I didn’t create any user yet.

Is it possible to create the first user of the system using mmctl?
(And otherwise, is it wise to open an issue for this?)

Hey @kemenaran

The first user that you sign up with in the system will always be a system admin. So you can use the UI and sign up as usual for that.

Alternatively, you can use mmctl in --local mode (mmctl Command Line Tool — Mattermost documentation) to perform operations without logging in.

I seems the local mode is exactly what I need. I’ll try that right away. Thanks for the advice!

Hi! I’ve a question about local mm user creation. How can we authorize on MM with local created user? As usually?

For example:

  1. I create user locally

email = “qwe@qwe”
name = “dan”
password = “password”
subprocess.run([“mmctl”, “–local”, “user”, “create”, “–email”, email, “–username”, name, “–password”, password,
“–firstname”, “firstName”, “–lastname”, “lastName”])

  1. I wanna auth with this user on MM to add another users, teams and channels. Should I do like this?

url = “some-url”
community_name = “test”
username = “dan”
password = “password”
subprocess.run(
[“mmctl”, “auth”, “login”, url, “–name”, community_name, “–username”, username, “–password”, password])

Hi KoloskovaMariia and welcome to the Mattermost forums!

Yes, authentication is the same as with other users, depending on your server configuration. If you support multiple authentication types (LDAP, email, etc.) you would need to specify the authentication backend upon user creation. The code snipped you posted will create a user account with email/password authentication.
In order to add users to a Mattermost installation, the user needs to be at least get the team admin permissions so they can send invites or create invite links which others could then use to create their own unprivileged accounts.
User creation using mmctl is only available for system admins AFAIK.

Thanks a lot! Now I know what to do in my work project!

Awesome, great to hear that :slight_smile: If you have further questions, please don’t hesitate to create a new issue here in the forums.