Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How do I copy file contents to my clients clipboard via SSH

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
jaytelford
Posts: 36
Joined: 2018-05-09 10:56
Location: United KIngdom

How do I copy file contents to my clients clipboard via SSH

#1 Post by jaytelford »

Hi,

Fairly new to Debian (moving from a Windows server environment to a Linux one and Debian was suggested)

I am running a headless server which I am accessing over SSH and I need to copy the contents of several files to paste into other locations that are not based on my server - Github SSH for example, and other places. I have installed xclip as I thought this would do the trick by doing this

Code: Select all

xclip -sel clip < ~/.ssh/id_rsa.pub
When I try to do this however, I get the following error message:

Code: Select all

Error: Can't open display: (null)
I have searched on Google and other places and found solutions.

SOLUTION 1:

Code: Select all

On the client:

1:  Open ~/.ssh/config
2:  Add X11Forwarding yes
3:  Save ~/.ssh/config

If the above file doesn't exist create it and then do steps 2 and 3

On the server"

1:  Open ~/.ssh/config
2:  Add X11Forwarding yes
3:  Save ~/.ssh/config

If the file doesn't exist on the server then create it
SOLUTION 2:

Code: Select all

Use this long string to specify the display:  DISPLAY=:0 xclip -sel clip < ~/.ssh/id_rsa.pub
Neither of these solutions work for me and I keep getting the same error message, saying that the display cant be opened and I don't know what I am doing wrong. Am I using xclip correctly, do I need additional packages to make xclip work on Debian? Also, is there a better clipboard tool that is easier to use and which will allow me to copy the contents of files into my clients clipboard so I can paste them elsewhere (off the server)

I feel really silly having to ask for help for something as simple as a clipboard tool, so sorry in advance for the noob question.

XD
Jay

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: How do I copy file contents to my clients clipboard via

#2 Post by Dai_trying »

I'm not sure if this is what you are looking for, but when I ssh into another machine and I want to paste clipboard contents to a file I simply create the file on the remote system (touch test.txt in ssh session) and then open it with nano (or whatever your preference is) and then on my local machine I can open a document in geany (or whatever you use) and select the text and Ctrl-c (copy to clipboard) and then in the terminal I can shift-Ctrl-V (or right click and select paste) and the information is in the document, then save and exit and the file is there with the contents I want.

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: How do I copy file contents to my clients clipboard via

#3 Post by debiman »

if the server is headless, and does not have a gui installed, and the ssh connection is to the text interface only, then your approach can't work.
yes, xsel only works in a graphical (typically Xorg) session. on the machine invoking it. the server, that is.
if you want text into the client machines clipboard, you would need some helper application on the client to take care of that.
sending the text itself to your client's ssh connection (another terminal i assume) isn't so difficult.

all in all, i find your requirement a little strange, and wonder if there isn't some fundamental misconception of what a (Linux) server is and how it works.

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1401
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 79 times
Been thanked: 175 times

Re: How do I copy file contents to my clients clipboard via

#4 Post by steve_v »

jaytelford wrote:I am running a headless server...
I have installed xclip...
I keep getting the same error message, saying that the display cant be opened...
xclip (and any other GUI applications) will try to connect to the xserver running on the same machine, so as to display the GUI on it's monitor. If it's headless, that is unlikely to work out.

To display the window of a GUI application running on the server on the client desktop, you will need to run an xserver on said client and forward requests with ssh.
Alternatively, go the "Windows server" way: Install X and the appropriate network daemon on the server, then connect to it with some remote desktop app. I like X2Go and Nomachine.
As a bonus, X2go supports both approaches. Try xrdp if you need Windoze "Remote Desktop" compatibility, though I can't vouch for how well it works.

All of this will of course be slower and more complicated than the CLI, so if you just want to grab some text you might want to do it one of the more traditional ways - say copy-pasting from the screen as previously mentioned, scp in a new terminal, or sending the contents back to a file e.g. via a reverse SSH tunnel.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

jaytelford
Posts: 36
Joined: 2018-05-09 10:56
Location: United KIngdom

Re: How do I copy file contents to my clients clipboard via

#5 Post by jaytelford »

Thanks for your replies.

It seems that I have miss-understood how xclip works. I had thought that it used the clients X environment over SSH, I didn't realise it had to be running in a GUI on the server itself. Copying the contents of files held on a Windows server environment was a lot easier by using remote desktop and allowing the remote to access local resources (like clipboard and so on).

It was a simple matter of

1: Opening the file using Remote Desktop
2: Selecting the text
3: Copying it in clipboard
4: Pasting it where-ever I wanted it to go

I could have an equivalent of Remote Desktop on my Linux server, but my server provider highly recommended that I did not. Not to worry, I can always scp the file to my client and then open the file from there and copy/paste the text where I want.

Like I say, all my experience has been in Windows environments and I am pretty new to Linux. Sadly because my business is pretty small, I cant afford to keep up with Microsofts stupid pricing policy and moving away from them has basically left me to do all the server admin on my own :( so please excuse any stupidly simple questions that I might ask.

XD
Jay

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 12 times
Been thanked: 66 times

Re: How do I copy file contents to my clients clipboard via

#6 Post by dilberts_left_nut »

Why not just use your client-side file manager (with sftp)?
AdrianTM wrote:There's no hacker in my grandma...

Post Reply