Invalid MIT-MAGIC-COOKIE-1/ksmserver could not start

I’m using Leap 15.0 with qt5 and kde frameworks 5 repos enabled. Lately, I couldn’t yet figure out under which circumstantces, I get “Invalid MIT-MAGIC-COOKIE-1 keyInvalid” messages when I start application from Konsole, e.g. vi (text vi!), oowriter etc.
These go away when I delete the ~/.Xauthority file (as suggested in some other thread) and kill the X server. But there’s also another very strange problem for which I also couldn’t figure out the circumstances under which it happens: sometimes after login, the desktop is already loaded, I have already started programs etc., I get a popup box saying: “Could not start ksmserver. Check your installation.” in which I can only click OK. Then I’m dropped back to the login screen with all of my work lost.

I suspect that these two problems are somehow related. Maybe that they have to do with upgrading from the plasma 5 sources or suspending/resuming the desktop. Can anyone help me figure out how to solve/debug any of these or at least give me a hint as to why these happen?
The first one with the invalid magic cookie is just annoying but seems to be harmless. But the second one is really troubling me as it might lead to data loss.

I have occasionally seen the invalid cookie message. I am not currently getting those.

I currently use GDM for login. My vague memory is that I got those messages when using “lightdm”. That is to say, I got those messages in desktop sessions where I had used “lightdm” to login. I’m not sure if there’s a connection.

It’s been a long time since I’ve had to troubleshoot this problem…

First, you need to be specific about what applications you’re trying to launch that’s throwing the error, generalization won’t help.
So,
You should not have any problem running vi.
Are you running as a normal User, invoking using sudo or in a full blown “su” root Konsole?

If you’re launching a graphical program, only some can be launched directly from a console… like YaST without a problem.
Many graphical programs in KDE cannot be launched from Konsole directly, particularly with root permissions, you may need to invoke

kdesu *application *

I seem to remember a different error though if you made the above mistake, you’d see a dbus error, not a Magic Cookie error…

TSU

I got the invalid magic cookie messages – and that also surprised me – when I launched vi (not gvim) as a normal user. Also with oowriter, or with mpv, with gnucash etc.

Sounds like you’re not likely “launching” vi the right way…
You’re not supposed to “launch” it like a graphical app which would cause the errors you describe,

You should first open a windowed console like Konsole if your Desktop is KDE, and then run vi within the console.

Depending on how those other apps are written, if they are text-based and not graphical, they should be “run” the same way.

TSU

If I remember correctly, I got those messages when launching an “xterm”, and probably when launching a “konsole” session.

However, I only saw that when I was experimenting with “lightdm”. I do not see it with “sddm” or with “gdm”. And I quickly stopped using “lightdm” for other reasons.

A possible insight as to what is going on, is to take a look at X11 Authorisation – “stackoverflow”: <https://stackoverflow.com/questions/37157097/how-does-x11-authorization-works-mit-magic-cookie>:

There are five standard access control mechanisms and they can be categorized in three main categories:
Access based on host
Access based on cookie
Access based on user

MIT-magic-cookie-1: Generating 128bit of key (“cookie”), storing it in ~/.Xauthority (or where XAUTHORITY envvar points to). The client sends it to server plain! the server checks whether it has a copy of this “cookie” and if so, the connection is permitted. the key is generated by DMX.

Taking a look at the situation on this machine:


 > xauth
Using authority file /home/???/.Xauthority
xauth> list
«a fully qualified host name»/unix:0  MIT-MAGIC-COOKIE-1  «128 bit key»
«a host name»/unix:0  MIT-MAGIC-COOKIE-1  «128 bit key»
xauth> info
Authority file:       /home/???/.Xauthority
File new:             no
File locked:          no
Number of entries:    2
Changes honored:      yes
Changes made:         no
Current input:        (stdin):2
xauth> quit
 > 

So, yes, if the 128 bit key used for the MIT Magic Cookie is corrupted, for whatever reason, the X11 session will have to be stopped (logout) and then, via a VT the user will have to delete the ~/.Xauthority file containing the corrupted key and, then, the affected user can login to their X11 session again …

First of all: I’m starting vi from a konsole window. After I close the text vim that opens, I see the messages:

me@linux-mymachine:~> vi
Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyme@linux-mymachine:~>

me@linux-mymachine:~> xauth
Using authority file /home/me/.Xauthority
xauth> list
linux-mymachine.site/unix:0  MIT-MAGIC-COOKIE-1  d30b064d2516247186bdcbf29c0a2458
linux-mymachine/unix:0  MIT-MAGIC-COOKIE-1  3295780b8d606fdd45ff18d8054fb5d8
xauth> info
Authority file:       /home/me/.Xauthority
File new:             no
File locked:          no
Number of entries:    2
Changes honored:      yes
Changes made:         no
Current input:        (stdin):2

I don’t get it: what’s wrong with that file/my machine/my setup? I still don’t know when this happens/what triggers this. It seemingly has no consequences: I can log in normally, all the programs launch without problems, it’s only these annoying messages when launching stuff. Well, and the occasional ksmserver problem.

I still suspect it has something to do with the suspending/waking but I just can’t put my finger on it.

Does it happen with a different user???

Also check the owner of ~/.Xauthaority ownership can be changed if you log into a GUI as root

Try deleting the ~/.Xauthaority file it should be recreated

If you do that, you should logout and then login again.

The generated MIT-MAGIC-COOKIE-1 values – 128 bit keys, with a value which you publish only if you really haven’t understood personal privacy – are corrupt.
Therefore:

  1. Logout from your KDE Plasma session.
  2. Login to a VT – tty1 or, tty2 or, tty3 or, tty4 or, tty5 or, tty6.
  3. Remove the file ‘~/.Xauthority’
  4. Login to your KDE Plasma session.

When you login again, after the file ‘~/.Xauthority’ has been removed, the file will be regenerated by the new X-Session with, new, valid, MIT-MAGIC-COOKIE-1 values …

The thing is: I know how to solve it (e.g. deleting the ~/.Xauthority and killing the X server) but I’d like to know what causes the invalidation and if I can prevent it.

N.B.: I published them because a different set seems to get recreated anyway after I have deleted the .Xauthority file, right?

The problem with the ksmserver seems to be connected to killing the X server after I deleted my .Xauthority file. After I logged in again, the .Xauthority file was recreated, I started vi, closed it, no invalid cookie messages. Then I cd’d to some directory and wanted to open oowriter, when the ksmserver error dialog popped up. I am not sure whether I actually hit Enter after typing oowriter mydoc.odt. But the X session was essentially destroyed, I could do nothing but click OK and restart the session.

Deleting the ‘.Xauthority’ file while a KDE Session and, therefore, an X11 Session as well as and also, is, something that one shouldn’t do – you can try it and, experience the pain, but, only if you’re into that sort of thing …

Please, please, please:

  1. Log out of the GUI session – KDE Plasma; X11; et al.
  2. Log in to a Virtual Terminal (VT) – tty1 or, tty2 or, tty3 or, tty4 or, tty5 or, tty6 – do this by typing “<Ctrl-Alt-F1>” or, “<Ctrl-Alt-F2>” or, “<Ctrl-Alt-F3>” or, “<Ctrl-Alt-F4>” or, “<Ctrl-Alt-F5>” or, “<Ctrl-Alt-F6>” to get the VT (no GUI) prompt.
  3. Then remove the user’s ‘.Xauthority’ file.
  4. Logout from the VT session.
  5. Re-attach to the GUI running on Virtual Terminal tty7 – type “<Ctrl-Alt-F7>”.