[SOLVED] Openhab default user password

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.
BUT
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?

Hello.

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"
	when
		Item raspberryRestart changed to ON
	then
		sendCommand(raspberryRestart, OFF)
		Thread::sleep(3000)
		val results = executeCommandLine("sudo /sbin/reboot", 5000)
		logInfo("reboot", results)
		//executeCommandLine("sudo reboot")			
end

(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

or

</> button

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

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
sudo ALL=NOPASSWD: ALL ###CHANGED

# 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"
	when
		Item openhabBackup changed to ON
	then
		sendCommand(openhabBackup, OFF)
		Thread::sleep(3000)
		val results = executeCommandLine("sudo sh /etc/openhab2/scripts/ohbackup.sh", 5000)
		logInfo("backupOHfiles", results)		
end

The script:

#!/bin/bash

# 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?
THX

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.

Thank you.

I tried one by one the following commands (all of them work, if i enter them directly via ssh):

rule "Backup OH-Dateien"
	when
		Item openhabBackup changed to ON
	then
		sendCommand(openhabBackup, OFF)
		Thread::sleep(3000)
		
		// https://community.openhab.org/t/openhab-default-user-password/4314/19
		
		//val results = executeCommandLine("sudo -i nohup sh /etc/openhab2/scripts/ohbackup.sh &", 5000)
		val results = executeCommandLine("sudo nohup sh /etc/openhab2/scripts/ohbackup.sh 0<&- &>/dev/null &", 5000)
		
		//val results = executeCommandLine("sudo su -c 'sudo sh /etc/openhab2/scripts/ohbackup.sh' -s /bin/sh root", 5000)
		//val results = executeCommandLine("sudo runuser -l  root -c 'sudo sh /etc/openhab2/scripts/ohbackup.sh'", 5000)
		
		// ### do geht moi gornix davon!
		
		logInfo("backupOHfiles", results)		
end

No command worked via OH2-Switch and the rule.

I also dont know if its necessary to stop OH2 for the backup, but thats the way its described in the oh2-wiki

none of that worked for me, running openhab on orange pi lite :tired_face:

[update]
was pure Linux permission issue, was trying to kill a process that is first run by pi user and kill it using openhab user.

http://docs.openhab.org/administration/console.html#accessing-the-console states the “The default username/password is openhab:habopen, so enter habopen at the password prompt.” Username in context is openhab, broader context is logging into the karaf console after having established an ssh session to the server.

Is that a question or an answer?

Sorry to upset anyone, but I was searching for my own needs for the answer same as this OP. The OP never got a clear answer in this thread so I thought I would post the solution that I found as an answer with finality and clarity to this OP.

1 Like

I don’t think there is anyone upset. You posting was a little ambiguous as written and it was hard to tell if you were asking a new question or posting an answer. Thanks for posting!

1 Like

:arrow_up: what he said :wink: