Reset cmkadmin password programaticly using bash script for example

Hi!

Is there a quick and easy way to reset cmkadmin password programmatically using a script for example?

I’m using raw - 2.1.0p19.

Thank you!

I’m not sure about the raw edition but the enterprise edition comes with the tool cmk-passwd:

OMD[mysite]:~$ cmk-passwd --help
usage: cmk-passwd [-h] [-V] [-n] [-i] username

cmkpasswd is a utility to add and change Checkmk user accounts in a
similar fashion to htpasswd. cmkpasswd will select a secure hashing
algorithm that is compatible with this version of Checkmk to protect
passwords. Note that the main purpose of this program is setting and
resetting the password for the cmkadmin user. For other tasks, such
as deleting or deactivating users, use the web interface.

positional arguments:
  username       the username of the user whose password to add or
                 change

optional arguments:
  -h, --help     show this help message and exit
  -V, --version  show program's version number and exit
  -n, --dry-run  don't write the result to the password file but
                 print to standard output
  -i, --stdin    read the password from standard input without
                 verification (useful for script usage)

The command would then be like

echo "new-passwd" | cmk-passwd --stdin cmkadmin

That does work! Thank you!!!

1 Like

Not sure if this is a best way to do it, but I wrote expect script to change password:

#!/usr/bin/expect

spawn omd su production
send -- "echo \"new-passwd\" | cmk-passwd --stdin cmkadmin\r"
send -- "exit\r"
expect eof
1 Like

I’m not familiar with expect and don’t know its syntax, but two questions:
What’s the difference or advantage over the simple command?
Isn’t expect usually used if the comand in question doesn’t accept input from stdin?

What about this then:

spawn omd su production
send -- "cmk-passwd cmkadmin\r"
send -- "new-passwd\r"
send -- "exit\r"
expect eof

Hi! My task is to change checkmk password inside script.

So running just echo "new-passwd" | cmk-passwd --stdin cmkadmin will not work, because first I need to run omd su production, what will open new “shell” where I need to put that command. At this point I found out that option for me would be to run expect script.

If you have any other options how to do it from bash/shell script besides expect script, please let me know.

Regarding your example of expect script, it might work, but frankly I don’t care more or less what is inside that script as far as it works.

My main agenda is to change password and seems expect script is way to go, I will be more then happy to find out about other alternatives.

Thank you!

You could run this:

su - production -c "echo 'new-passwd' | cmk-passwd --stdin cmkadmin"

2 Likes

Exactly. Or, if you are more used to sudo instead of su (like me), then:

echo "new-passwd" | sudo -u production -i cmk-passwd --stdin cmkadmin
2 Likes

Great! Thank you that even better!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.