X11-Forwarding with Magic-Cookie

Problem

X11-Redirection to users desktop is quite simple. But if you switch the user in the ssh-session for security-reasons you have to deal with the Magic-Cookie.

Solution with Magic-Cookie

This command creates two files in the temp-Directory that are run with the other user

echo export DISPLAY=$DISPLAY >/tmp/disp
echo xauth add `xauth list ${DISPLAY#localhost}` >/tmp/mc
chmod +x /tmp/disp;chmod +x /tmp/mc

sudo su - oracle
. /tmp/disp;. /tmp/mc;xclock

 

Hinterlasse einen Kommentar