Question

After changing the hostname gedit is not working as expected, it shows error always in my root "No protocol specified"

** (gedit:23330): WARNING **: Could not open X display
No protocol specified
Cannot open display: 
Run 'gedit --help' to 
Was it helpful?

Solution

It's not only gedit that is going to fail but actually all programs that use the X11 protocol to talk to the graphics server. X11 uses the Xauth protocol to authenticate connecting clients. When you login through some kind of a display manager, a MIT-MAGIC-COOKIE-1 authentication cookie is created and written into your ~/.Xauthority file. That file is read by X11 clients and the cookies available there are used to authenticate the connections.

The list of cookies in your ~/.Xauthority file can be displayed using xauth list:

$ xauth list
localhost:1012  MIT-MAGIC-COOKIE-1  bd988401cbf8xxxxxxxxxxxxxxxxxxxx
some.host.example.com/unix:1012  MIT-MAGIC-COOKIE-1  bd988401cbf8xxxxxxxxxxxxxxxxxxxx

If you change your host name, the X11 client library will no longer be able to find a matching cookie in the authentication database and the X11 server will reject the unauthenticated connection (unless configured otherwise).

What you can do is to add a matching cookie using xauth:

$ xauth add "$(hostname)/unix:0" MIT-MAGIC-COOKIE-1 bd988401cbf8xxxxxxxxxxxxxxxxxxxx

$(hostname) expands to the result of the hostname command and unix:0 corresponds to your DISPLAY environment variable being set to :0.0. If it is to another display number, e.g. :ddd.0, then you should change the added host entry accordingly to "($hostname)/unix:ddd". Note also that the value of the cookie being added should match the value of the existing one.

If you don't have a terminal emulator open at that time and you are unable to open one because of the authentication error, you could switch to the console (text mode), login there and execute the above command.

OTHER TIPS

Simply restart the machine to take effect the hostname change.

jnweiger commented Aug 13, 2014:

The Xauthority file can be written in a way so that the hostname does not matter.

I am not sure, if xauth has a proper command line to specify the Authentication Family, but I use sed to switch to Authentication Family 'FamilyWild'. We need to change the first 16 bits of the nlist output. The value of FamilyWild is 65535 or 0xffff.

xauth nlist :0 | sed -e 's/^..../ffff/' | xauth nmerge -

In this case, the string written after the family number (usually, a hostname etc.) does not matter for matching at all.

In ALT's xauth package, there has been applied a patch recently to support adding such FamilyWild entries via xauth directly with an *:0 argument:

From bc78aa61cfbddaa27dee275f639ba40de6981b17 Mon Sep 17 00:00:00 2001
From: George V. Kouryachy (Fr. Br. George) <george@>
Date: Fri, 4 Aug 2017 18:37:33 +0300
Subject: [PATCH] parse_displayname: use FamilyWild for *:0

---
 xauth/gethost.c  |    4 ++++
 xauth/parsedpy.c |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/xauth/gethost.c b/xauth/gethost.c
index 8cb58c5..598ac48 100644
--- a/xauth/gethost.c
+++ b/xauth/gethost.c
@@ -180,6 +180,10 @@ struct addrlist *get_address_info (
      * information to be copied and set len to the number of bytes.
      */
     switch (family) {
+      case FamilyWild:         /* was :0 */
+   src = "\xff\xff";
+   len = strlen(src);
+   break;
       case FamilyLocal:            /* hostname/unix:0 */
                    /* handle unix:0 and :0 specially */
    if (prefix == 0 && (strncmp (fulldpyname, "unix:", 5) == 0 ||
diff --git a/xauth/parsedpy.c b/xauth/parsedpy.c
index 97988d3..6c98339 100644
--- a/xauth/parsedpy.c
+++ b/xauth/parsedpy.c
@@ -141,6 +141,10 @@ parse_displayname (const char *displayname,
        family = FamilyInternet;
    }
 #endif
+    } else if (len == 1 && *displayname == '*') {
+   /* ALT: wildcard cookie */
+   host = copystring("*", 1);
+   family = FamilyWild;
     } else if (!dnet && (*displayname == '[') && (*(ptr - 1) == ']')) {
    /* Allow RFC2732-like [<IPv6NumericAddress>]:display syntax */
    family = FamilyInternet6;
-- 
1.7.3.3

When I changed the name of my laptop I experienced this problem as well. However I managed to fix it with the following commands

su

(enter password)

cd /etc

gedit hosts

From there I simply removed the reference to the old computer name and replaced it with the new.

127.x.x.x localhost 127.x.x.x (New Name)

However Note that whenever you make changes to your computer name, you must ensure that the changes are made in both the /etc/hostname file as well as the /etc/host file. If you make 1 change without making the other, you will get an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top