4

I want to copy a long file into clipboard with xsel,in my local pc ,just input:

cat /usr/bin/mysql_secure_installation|xsel -b

The file mysql_secure_installation located in my local os was copied into clipboard.

Now login to my vps with ssh command,then input

DISPLAY=:0 cat /usr/bin/mysql_secure_installation|xsel -b

I come across the error info:

xsel: Can't open display: (null)
: Inappropriate ioctl for device

I know that the proper way to get remote file is scp command:

scp -P port username@tohostname:/remotefile /newlocalfile

I just wonder how to get file content copied into clipboard after loginning my vps,copy file from remote machine to the clipboard of my local computer.

Same error:

DISPLAY=:0 xsel -b <  /usr/bin/mysql_secure_installation
xsel: Can't open display: (null)
: Connection refused
2
  • 1
    So you try to copy file from remote machine to the clipboard of your local computer, right? Feb 6 '20 at 10:15
  • 1
    try running it as DISPLAY=:0 xsel -b <foo or ... | DISPLAY=:0 xsel -b instead of DISPLAY=:0 cat ... | xsel -b which will only set the DISPLAY envvar for the cat process.
    – mosvy
    Feb 6 '20 at 11:39
3

Start your ssh connection with

ssh -X yourserver

then don't change the DISPLAY variable yourself. ssh should set it up automatically, so that xsel (and any other X11 clients) can use the display on your local computer -- including its clipboard. This is called X11 forwarding.

Manually setting DISPLAY=:0 in your ssh session will tell xsel to use the display on that remote server -- if one is even running.

4
  • I couldn't get this working. xsel: Can't open display: (null) : Inappropriate ioctl for device
    – Ryan
    Feb 7 '20 at 16:01
  • 1
    @Ryan What is the value of DISPLAY when you do this? If you enable debugging messages with ssh -v, does it including anything about X11 forwarding?
    – JigglyNaga
    Feb 7 '20 at 16:24
  • Interesting. I see debug1: No xauth program. Warning: untrusted X11 forwarding setup failed: xauth key data not generated
    – Ryan
    Feb 7 '20 at 17:54
  • Maybe you are talking about: stackoverflow.com/a/39556508/470749 (I will look at my client and server configs.) I'd also asked a question here: stackoverflow.com/q/60117294/470749
    – Ryan
    Feb 7 '20 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.