Adding permanently at boot: xhost local:root

Hello,
I want to run Backintime as root but I had the error message

No protocol specified
Error: couldn't open display :0

I found the issue: I need to add

xhost local:root

But this is only temporary, I want it permanently. I can’t find a easy way to do it.
Where and how to add this command in the boot process that could be helpful for any application running as root/GUI?

Thank you for your help

How? from a CLI session on the console?

I usually run from the GUI menu as root but I tried from the CLI to get the error message.
After enter

xhost local:root

from the CLI, both CLI and menu are working.
So, I need to set it permanent.

You are touching a very basic problem. Just think it over. There is a CLI session run by a user (that it is root is not important at all). Now this user starts a GUI program. What to do?

You seem to think that it is “logical” that

  • there is by incident also a GUI session running at that moment inn time;
  • that there is only one of that kind (else which one to choose?);
  • the users there, which is another user then the one starting the program, is happy to allow that other user to one (or more) windows on his desktop.
  • and that then the windows belonging to user A on the CLI session are displayed on the GUI session of user B.

The Unix/Linux designers decided that that is not logical at all and that such circumstances can only all be true at the same moment by incident. Also that security forbids to allow user A to open a window on the display of user B without her/his explicit allowance.

So even if there is at least and at most one GUI session open, the owner of that session must alow other(s) to open windows. And that can (under circumstances) be done with a xhost commando. But that xhost commando is to be done by that user in his/her session. Like you already found out. It is nothing that can be done on boot (it is not a system action at all). It could be done by the user by e.g. executing the xhost in the programs to be started on login (many DEs allow such configurations.

But remind that even when that user allows root on the localhost to open windows on his/her display, it is not sure that that user is logged in when root wants this.

I had reading on what you explained and I understand the security issue and the consequent design.
I didn’t express myself in the right way; This is not at boot that I want to set this command but at logging.
I run my personal computer without other user and it boot then log by itself, this is why I wrote a stupid request.

So where to place the command in the logging process?

Add script in /etc/X11/xdm/scripts

that could be helpful for any application running as root/GUI?

As already mentioned, it is of questionable merits.

The above solution may work for you independent of the user.

If you want to do that with the starting of the Desktop by a user, then you have of course at least explain which desktop that user is using which you kept secret all the time.

I use MATE DE.

[QUOTE]that could be helpful for any application running as root/GUI?
As already mentioned, it is of questionable merits.[/QUOTE]
What if I write the command in the GUI command line?
At present time I have in the menu Launcher properties command

/usr/bin/backintime-qt4_polkit %f

Can I write

xhost local:root; /usr/bin/backintime-qt4_polkit %f

More security and easier.

I never used MATE, so I will refrain from advising here.

In kDE there is somewhere a directory where you can place scripts to be started at login. A script could look like

#!/bin/bash
xhost ........

(and do not forget to set the x-bit for the user).

In fact I do not realy understand your case.
You are logged in in the GUI as user (let us say) mrnice. So the only thing to do is start your application from the command line there with something like kdesu.
Instead you do a Ctrl-Alt-f1 (or F2), and log in as mrnice, after which you use

su -

to “become root”. And then you start that GUI application. I do not see what that brings you.

In fact I do not realy understand your case.

Easy: System boot and auto log as mrnice. Then I want to start Backintime from the menu > Applications > System Tools > Back in Time (root)
It was working fine when I installed it but few months ago stopped for some reason (update?)

The menu launches the appli with the command

/usr/bin/backintime-qt4_polkit %f

- After enter xhost local:root in the CLI, in the CLI, the same command is not working with the parameter %f but working fine without it.
- After enter xhost local:root in the CLI, Backintime start fine from the menu

I tried to change the command in the menu

xhost local:root; /usr/bin/backintime-qt4_polkit %f
or
/usr/bin/xhost local:root && /usr/bin/backintime-qt4_polkit %f

but the appli doesn’t start.
I tried with ; and && between the 2 commands. It looks like the menu can’t run 2 chained commands.
Could you confirm?
I’ll have to use the script (not easy for me I never did it).

So you have a problem possibly started by an update, but instead of trying to solve that (either on your own, or by trying to get help here), you are wandering in all sorts of by-passes which make things more difficult to understand and to execute?

I’d guess you are right but I am not skilled as you and I try to fix in the way it’s look easier for me. Maybe I am wrong.

I go further; This current install Leap 15.1 is an upgrade from a older version for more than 2 years. I have some issues with other applications (firefox can’t keep the window size, I need to enter the key ring…) and this one. I think to reinstall from scratch but no time right now. I try to keep working what I can. So if I can’t fix the xhost, I’ll keep note the “xhost local:root” command and just enter it in the CLI just before I run Backintime from menu, not often at all.

BTW, my SSD is ext4 formatted, I can’t go back

You advices are welcome but without, I’ll leave like that.
Thank you

I still think it is much better to address your peoblems as you find them by using the expertise here on the forums then just meddle around and going deeper and deeper into troubles.

And for this specific subject, I still do not understand why running from the GUI a terminal application (I do not know what MATE uses, on KDE one would use konsole and all have xterm), there “become root” with

su -

and then start the application. Because that is from that GUI session, there will be no problem for windoes to be opened. Like YaST.

Please try that and show here what happnes (until now we have only your story and almost no computer evidence).

I still do not understand why running from the GUI a terminal application
There is a misunderstand, sorry I am not a English language native.
I use the menu to start BackinTime. I started it from the terminal only to get the error message.

After closer inspection, I found why it was not working fine:
After install, Backintime has 2 menu item:

  • Back in Time >>> the command in the menu properties is backintime-qt4
  • Back in time (root) >>>> the command in the menu properties is /usr/bin/backintime-qt4_polkit %f
    Each of them has its own config file.

As I want to backup the /etc directory, I need to start it as root. But for some reason, I mixed up the user and root start menu. I had the user config with /etc dir to be backup and root without it. User config can’t save system files and doesn’t save the backup at all.

Now I understand my mistake, it should run properly.
I removed anacron from the user config and edit the MATE menu to hidden the user Backintime and leave only root. I’ll seldom have to start the root menu, so I’ll use the xhost command manually before. I keep security.

I hope you understand, this was only my mistake.
Anyway thank you for your commitment.

As others have noted and I’ll also re-emphasize,
invoking xhost is a poor way to run an application, so all alternatives should be explored before going down this path as a last resort.

Taking a look at the backintime project page
https://github.com/bit-team/backintime

It says that a command line utility called “backintime” is installed, and if that’s true then you should invoke that to see what it does (User Documentation is very sparse).
Source says that a MAN page should be created which means that full documentation should display with

man backintime

This means that it’s likely that using backintime in a script or at least in a command line can be found by reading the following
https://linux.die.net/man/1/backintime

As an aside,
You should <not> use the following for complex scripting, but can manage the graphical backintime with commands found in MAN backintime-qt. Note their recommended method for executing as root (pkexec). I assume that “su -” (likely in this case requires full root environment) followed by executing the given commands should work also.
http://manpages.org/backintime-qt4

HTH,
TSU

Congratulations, you solved it!

We all make mistakes and it is this sort of discussions on forums which in the end give you hints to look somewhere, to rethink something, etc.

We are glad we could have been of help.

Enjoy openSUSE.