Reputation: 547
I have a main user that X runs under: username1. I have another user account which I do a lot of work in, username2.
How do I make it so that I can copy the output of a command from userame2 into username1s clipboard.
Here is an example of it failing:
username2 $ echo "hello" |xclip
No protocol specified
Error: Can't open display: :0
Looking online, I found I should change the DISPLAY variable.
Here is what I get after making that change:
username2 $ echo "hello" |xclip
Error: Can't open display: myws:0
When searching, I also see that there may be something I will need to do with my .Xauthority file; however I am unfamiliar with it. I will continue to review the documentation.
Any advise would be greatly appreciated.
Upvotes: 3
Views: 1905
Reputation: 775
Being able to write to another users clipboard would be a HUGE security issue. Luckily there is one user we can trust (or at least we are supposed to), root. So assuming your shell-only user (username2) has root privileges (like sudo).
username2 $ export DISPLAY=:0
username2 $ export XAUTHORITY=/home/username1/.Xauthority
username2 $ echo "hello" | sudo xclip
We set username2's DISPLAY
variable to :0
in order to tell X the screen we are dealing with. If you have control of username1 you can simply echo $DISPLAY
to see the value, if you don't then you can run the commands w
or who
to see the value.
Next we set XAUTHORITY=/home/username1/.Xauthority
to handle all that authorization/security nonsense. Now username2 can't read this variable but root certainly can (or username1 could chmod a+r ~/.Xauthority
to give everyone read access).
Note: Tested on stock Ubuntu 12.04 LTS
Upvotes: 1