How To Create User in Mattermost with mmtcl?

I Wanted to create user with mmctl command on local server Ubuntu 20.04.5 LTS with this command :

** /opt/mattermost/bin/mmctl user create --email s.chalian@… --username s.chalian --password 12345678 **

but gives me this error

Error: cannot read user credentials, maybe you need to use login first: stat /root/.config/mmctl/config: no such file

Link of documentation that i,ve used for this

Hi Zahra and welcome to the Mattermost forums!

mmctl requires authentication, even if you’re on the same server as the Mattermost application server is running, but you can circumvent the username/password authentication by using local socket based authentication, which basically means that you can connect internally to the Mattermost server, without the extra need to authenticate yourself.
In order to do that, you would have to add the --local flag to mmctl and you will need to enable the local authentication mode and restart your Mattermost server for the changes to become active.
To enable local mode, open your Mattermost server’s config.json file and search for EnableLocalMode which most likely is set to false in your environment. Change it to true, restart the server and the mmctl command from above (with the additional --local flag added) should work now.

If you’re using a docker deployment, you will have to use the environment variable MM_SERVICESETTINGS_ENABLELOCALMODE instead of modifying the config.json directly.

1 Like

I enablelocalmode true after your suggestion restarted the server and still get an error

/opt/mattermost/bin/mmctl user create --email jarvis.cabarcas@jhsmiami.org, --username jcabarcas --password cab-J00@ --system-admin --local
Error: owner of the file “/var/tmp/mattermost_local.socket” must be the same user running mmctl

What owner does

ls -l /var/tmp/mattermost_local.socket

reveal? What user are you running mmctl as?

You should be able to create a POSIX user group that contains the mattermost user and your user account and make it thr group owner of /var/tmp/mattermost_local.socket

You can also

su -u mattermost_user mmctl...

still didn’t work. sudo -u mattermost $(which mmctl) --local... did the thing.