[SOLVED] Openhab default user password

Sometimes I struggle with access rights.
So for testing pusposes I would like to run scripts etc as “openhab”.
Unfortunately I cannot switch to openhab because I do not have the password, nor would I like to change it through root, because I don’t know what will happen to the openhab installation in general.
What is the default password of user “openhab” in the apt-get installation of openhab?
Sorry for this possibly stupid newbie question.

I think the openhab user is a special no-login user. In Linux there are a number of user accounts that cannot be logged into. For example, on Ubuntu you cannot log in as root nor can you su to root. I suspect the openhab user is the same.

However, you can sudo -u openhab <command> to execute a script or a command as the openhab user.

Great, thanks, Rich.
That’s the information I was looking for.
But when I execute my script
sudo -u openhab /usr/share/openhab/configurations/scripts/bt.sh 1
the system requests a password anyway :frowning:

It is requesting your password in this case, not openhab’s password. For example, if you are on a RasPi and logged in a pi, you would type in pi’s password.

Hi Rich,
the pi password is not accepted and the shell asks for the sudo openhab password explicitly:
[sudo] password for openhab:

Sorry, I should have shared this earlier.
Any other suggestion?

Hmmm. I’m running openhab on Ubuntu so perhaps it works differently.

On the pi you should be able to su to root and then su to openhab. Once you are root you don’t need a password to su to another account, usually.

Thanks for your patience.
I get the same result though:
I switched to root and executed
sudo -u openhab /usr/share/openhab/configurations/scripts/bt.sh 1
Which results in a password request for openhab again:
[sudo] password for openhab:

su to root. Then su to openhab. Don’t sudo.

Sorry, for reading not properly :wink:
When I su to root and afterwards to openhab I don’t need a password so far so good.
When I run my script, I get the right result.
I get a “root” when I check by whoami.
So that means I am still root and so the script MUST work.
But within openhab the user is the “real” openhab user, right?


Old topic but it matches my problem.

I am not able to restart my Raspberry via Switch (in OH1 i was but now after apt-get install i am not).
It runs with KODI (i think thats jessie 16 or so). But as i said it worked with the same RPI and OH1 perfectly.

The rule is: "executeCommandLine(“sudo reboot”)"
Execution is in the log.
2016-12-04 10:51:55.827 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'sudo reboot’
But nothing happens.

Maybe anyone can help me (i am not very used to Linux and its user permissons and so on).

Is the openhab user configured in sudoers? Is the openhab user configured to not require a password in sudoers? It is also possible that the openhab user does not have the reboot command in its path. Try using the full path (run which reboot and it will give you the path).

You can find out what that command is doing by adding a timeout and “catching” the result.

val results = executeCommandLine("sudo reboot", 5000)
logInfo("reboot", results)

Old topic but just to answer the original question:
The openhab user doesn’t have neither password nor shell. Therefore you need to go about it a bit special:

sudo su -s /bin/bash -c '/usr/share/openhab2/runtime/bin/client' openhab

Hi Rick and thank you.
Here are my results:

Openhab log (the same result with “sudo reboot” and also with “sudo /sbin/reboot”):

2016-12-10 08:50:06.394 [INFO ] [ternal.communicator.HomematicGateway] - No event since 49917 seconds from gateway 'ccu', restarting RPC server
2016-12-10 08:50:06.592 [INFO ] [ng.homematic.internal.misc.MiscUtils] - Datapoint name 'Alarmzone 1' contains invalid characters, new Datapoint name 'Alarmzone_1'
2016-12-10 08:50:08.408 [INFO ] [clipse.smarthome.model.script.reboot] - 
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

Content of visudo:

# User privilege specification
root    ALL=(ALL:ALL) ALL
openhab  ALL=(ALL:ALL) ALL
osmc    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

My whole Reboot-Rule:

rule "Restart Raspberry"
		Item raspberryRestart changed to ON
		sendCommand(raspberryRestart, OFF)
		val results = executeCommandLine("sudo /sbin/reboot", 5000)
		logInfo("reboot", results)
		//executeCommandLine("sudo reboot")			

(Maybe you already know that this forum changes lines with a # at the beginning to a BOLD line)

Formatting corrected by moderator

Put logs in three backticks or use the </> button, then it will display correctly and is easier to read:

three backticks


</> button

#Allow members of group sudo to execute any command

I had the same problem. But now it works with the following adjustments (I am using Jessie as well):
Actually I was not able to make it run from executeCommandline directly (without the script).

In a rule I execute a script:
executeCommandLine("/etc/openhab2/scripts/rebootHomer.sh", 10000)

Which contains mainly:
sudo /sbin/reboot

and my sudoers file contains:
openhab ALL = NOPASSWD: /sbin/reboot

Hope this helps.

1 Like

@NCO has the answer. The errror sudo: no tty present and no askpass program specified means that the openhab user is required to enter a password yet no password was provided and there is no way to ask for a password.

Configure openhab to not require a password and the error will go away.

1 Like

Thanks nco and rick.
Now it works.

To figure out how to configure visudo correctyl i visited following forum:

So now visudo looks that way (the line ending with ###CHANGED is the important one):

# This file MUST be edited with the 'visudo' command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
openhab ALL=(ALL:ALL) ALL
osmc    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

Update: It seems this wos not enough. I also had to enter following 2 commands when i set up a new oh2-Raspberry:
sudo usermod -aG root openhab
adduser openhab sudo
Now it works on the new raspi.

So now sudo reboot works via OH2-Switch.
But now an other switch should backup the oh2-config.
The rule is:

rule "Backup OH-Dateien"
		Item openhabBackup changed to ON
		sendCommand(openhabBackup, OFF)
		val results = executeCommandLine("sudo sh /etc/openhab2/scripts/ohbackup.sh", 5000)
		logInfo("backupOHfiles", results)		

The script:


# stop openhab instance (here: systemd service)
sudo systemctl stop openhab2.service

# backup current installation with settings
TIMESTAMP=`date +%Y%m%d_%H%M%S`;
mkdir  /media/kodifredi/openhab/openhab2-backup-$TIMESTAMP
cp -arv /etc/openhab2 /media/kodifredi/openhab/openhab2-backup-$TIMESTAMP/conf
cp -arv /var/lib/openhab2 /media/kodifredi/openhab/openhab2-backup-$TIMESTAMP/userdata

# Archivieren und Ordner löschen
#sudo tar cfzv openhab2-backup-$TIMESTAMP.tar openhab2-backup-$TIMESTAMP
#sudo rm -r openhab2-backup-$TIMESTAMP

# restart openhab instance
sudo systemctl start openhab2.service

When i execute the sudo command in ssh terminal, evrything is ok, but when i press the switch on the sitemap, it seems that only the first order to stop oh2 is executed. no files get copied and also the start oh 2 line does not get executed.
Maybe anyone knows a solution or a workaround for that?

Yeah, because you are stopping openhab. The script is running in a subshell of the openhab process, so when you kill openhab, you kill the script.

Not sure how to get around it off the top of my head… Let me have a think.

Try running the sudo with -i to use a shell.

Also, is it actually necessary to shut down openhab when taking a backup? Not sure if it is.