Linux “X11 Connection Rejected Because of Wrong Authentication” Error and Solution

I have set up X desktop and want to connect to the X server through ssh. As you know ssh provides X forwarding which is a very useful feature and used a lot of system administrators.

Try To Connect Ssh X Forwarding

We will try to connect the X service of remote ssh server by providing -X parameter.

$ ssh -X ubu1

OR

$ nautilus
Try To Connect Ssh X Forwarding
Try To Connect Ssh X Forwarding

We get an error like “Unable to init server: Could not connect: Connection refused” or  “/usr/bin/xauth:  /home/ismail/.Xauthority not writable, changes will be ignored”

Change Ownership Of Xauthority

We will change Xauthority file ownership because it will be used by the current user to read and write.

$ sudo chown ismail:ismail .Xauthority
Change Ownership Of Xauthority
Change Ownership Of Xauthority

Check Disk If It Is Full

One of the root cause of a lot of problems is fulling disk. It is a hidden problem and generally does not show himself. We should all ways count this option for troubleshooting.

$ df -lh
df -lh

As we can see in the third line of output our root path have enough free space to run X

Check Ssh Server X Forwarding Setting

The ssh server configuration has a line X11Forwarding which enables or disable X11 forwarding. It may be disabled because of security reasons.

$ cat /etc/ssh/sshd_config  | grep X11Forwarding
X11Forward

Check Ssh Client ForwardX11 Setting

The client-side of the ssh configuration also includes X11 forwarding. It shouldn’t be disabled or explicitly enabled like below.

$ cat /etc/ssh/ssh_config | grep ForwardX11
Check Ssh Client ForwardX11 Setting
Check Ssh Client ForwardX11 Setting

We should uncomment line ForwardX11 no and change to yes.

Leave a Comment