I am new to Linux and have set up the following version of Ubuntu as a VirtualBox VM using this process:
ubuntu-20.04.3-desktop-amd64.iso
The first account created was a administrator account. I installed xsel
and checked that it worked. I then created a non-administrator account and su
d into it with su - non-admin-account
. At that point, xsel
complains:
xsel: Can't open display: (null)
: Inappropriate ioctl for device
What do I have to do to make xsel
accessible after su
ing into another account?
Presently, I'm not interested in starting apps that launch their own client windows when su
'd into the non-administrator account. I just want simple piping of standard out to the clipboard so that I can retrieve it in Vim or the Bash command line using Shift+Ins, e.g., echo dog | xsel -ib
or echo dog | xsel -ip
.
My current plan is to write or redirect to (say) /tmp/tmp.txt
to pass text between a user that logged in from a login screen versus one that was su
d to. I'm used to Cygwin's behaviour, where the clipboard is shared regardless of which account a terminal is started under.
Troubleshooting
I get the same behaviour if I log into the non-administrator account and su
to the administrator account. xsel
works in the non-administrator that I log into, but not the administrator account that I su
to.
Essentially, xsel
doesn't work after an su
.
As per the comments, I looked at this problem's answers. I don't recognize the problem description, as the error messages are quite different, so someone looking based on error messages won't recognize that question. Furthermore, I don't understand the answers. The bit that looked like it might apply to my solution was xhost +localhost
, but it didn't work because the syntax is wrong, at least for the Ubuntu version I'm using. I post the syntax that does work in my answer below.
I think that before that above cited page can even remotely inform someone, you have to know that the problem is the lack of permission for an account to access the X server. For example, if you come from a background of using Cygwin's X-windows, you would probably not guess this because the problem doesn't manifest itself there.
man xhost
, and do something likexhost +localhost
before thesu
. That will open up the "display" to every user onlocalhost
. – waltinator Nov 04 '21 at 05:53xhost +SI:localuser:nonadmin-username
, which yieldedlocaluser:nonadmin-username being added to access control list
. I then issuedsu - nonadmin-username
andls | xsel -ip
andls | xsel -ib
, but I get the same error as above. I need to read and experiment more. As per the linked page, issuingxhost
from the admin account yieldsSI:localuser:nonadmin-username
andSI:localuser:admin-username
. – user2153235 Nov 04 '21 at 07:23su
ing to nonadmin-username, I issuedexport DISPLAY=:0
to match the variable's value in the admin account. Thenls | xsel -ip
didn't generate any messages (good), suggesting that the text was sent to the "PRIMARY selection" buffer. I then exitted from thesu
session and issuedcat
from the admin account so that I can paste the text via Shift+Ins (emulates X11 middle-mouse-button click). It behaved as expected. Thanks! Did you want to post the answer? – user2153235 Nov 04 '21 at 07:32xsel
which is an X11 application. What do you actually want? – Toby Speight Nov 11 '21 at 15:26