My regular user account is, let's say, user1. I created separate user2 for some x application that i would like to run while being logged into x as user1 but in a way that will prevent it from read/write access to user1 data. I thought that i could use xauth and sudo/su to user2 from user1 to run this application. How do i do this? I'm not sure how to configure xauth.
To use xauth selectively, as user1 run:
This prints the hexkey authorization entries for you . You could have different displays associated with those hosts as well.
As user2 set your display (assuming default case):
Then run:
Note the dot after the $DISPLAY and before the hexkey.
When access is no longer needed, as user2 you can run:
I put in my
.zshrc
a line withexport XAUTHORITY=~/.Xauthority
and now I am able to executesudo -E xcommand
. After a lot of googling, for me this was the easiest way.First: Don't use
xhost +
, it's rather insecure (blanket allow/deny).Rather use the X-Cookie mechanism:
Alternatively, if you have
sux
installed, use that (see ehempel's answer).In both cases user2 will use the secret cookie in .Xauthority to authorize to the X server, and no one else will have access to it.
Notes:
.Xauthority
, you can also usexauth
to extract and copy the authorization key (see Randall's answer). If you have multiple keys in the.Xauthority
file this is more selective; otherwise it is a matter of taste.Assuming debian or ubuntu (should be similar on Red Hat / SUSE).
This will fix the problem for all users:
As root:
Where yourusername is your user name :)
Then do su as your user
xclock
should work if it's installedSome other options:
xauth +
(unsecure) (doesn't work on recent versions ofxauth
)ssh -X user2@localhost
(ugly, but might be simpler to get to work than direct authentication)I found something that works great for me on KDE
This way made in suse/opensuse : http://www.novell.com/support/kb/doc.php?id=7003743
Simply modifying the /etc/pam.d/su, adding the option (bold) :
Then you can switch with su without - :
and run the app graphically.
For GNOME (and without any desktop environment really, I use it with icewm only)
gksu
: