Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing bash script for X-11 forwarding

Tags:

bash

unix

I was having problem with SSH X-11 forwarding while I used sudo. I found a solution for it.

$hostname
server4.a.b.edu

First I do:

$ echo $DISPLAY
localhost:10.0

then

$ xauth list
server1.a.b.edu/unix:12  MIT-MAGIC-COOKIE-1  6026864294a0e081ac452e8740bcd0fe
server4.a.b.edu/unix:10  MIT-MAGIC-COOKIE-1  f01fbfe0c0d68e30b45afe3829b27e58

Then I need to do

$ sudo xauth add server4.a.b.edu/unix:10  MIT-MAGIC-COOKIE-1  f01fbfe0c0d68e30b45afe3829b27e58

for sudo to work, for the cookie with my server name and display.

How do I write a bash script to automate this?

like image 830
Bruce Avatar asked Sep 15 '26 04:09

Bruce


2 Answers

One thing that worked on RHEL6 was exporting the XAUTHORITY variable before sudoing, for example:

export XAUTHORITY=~/.Xauthority
sudo xclock
like image 198
Joao Gustavo Avatar answered Sep 17 '26 20:09

Joao Gustavo


You shouldn't need a script at all; it's just a single command.

sudo xauth add `xauth list $DISPLAY`
like image 34
evil otto Avatar answered Sep 17 '26 22:09

evil otto