Search This Blog

X11 display forwarding for root

  • The problem:
    [wilson@local-host]$ ssh -Y -A -t -C -o CompressionLevel=9 wilson@remote-host
    [wilson@remote-host]$ sudo su
    [root@remote-host]$ xclock
    X11 connection rejected because of wrong authentication.
    Error: cannot open display: localhost:10.0
    
  • The solution:
    [wilson@local-host]$ ssh -Y -A -t -C -o CompressionLevel=9 wilson@remote-host
    [wilson@remote-host]$ sudo su
    [root@remote-host]$ su - wilson -c 'xauth list' | grep $(echo $DISPLAY | cut -d ':' -f 2 | cut -d '.' -f 1 | sed -e s/^/:/) | xargs -n 3 xauth add
    [root@remote-host]$ xclock
    

See also

1 comment:

  1. wow, thank you so much for this! I was looking all over but couldn't seem to figure it out. this let me run gparted on my headless raspberry pi through ssh -X!

    ReplyDelete