How I fixed SSH X-forwarding error "X11 connection rejected because of wrong authentication"
Problem:
I connected to my server with X forwarding using
example.txt
ssh -CX user@server
but when I start a graphical application on the server, I see the following error messages:
example.txt
user@server $ gparted
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused
(gpartedbin:70357): Gtk-WARNING **: 00:06:19.612: cannot open display: localhost:11.0
Solution
I found the solution in this StackOverflow post:
example.sh
sudo --preserve-env=DISPLAY -s
xauth merge /home/user/.Xauthority
Note that you have to replace /home/user
with the appropriate home directory.
Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow