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

New to Debian (Or Linux in general)? Ask your questions here!

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

Postby jaytelford » 2018-05-09 14:25

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
jaytelford
 
Posts: 6
Joined: 2018-05-09 10:56
Location: United KIngdom

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

Postby Dai_trying » 2018-05-09 16:43

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.
Dai_trying
 
Posts: 422
Joined: 2016-01-07 12:25

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

Postby debiman » 2018-05-09 17:38

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.
User avatar
debiman
 
Posts: 2209
Joined: 2013-03-12 07:18

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

Postby steve_v » 2018-05-10 04:56

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.
steve_v
 
Posts: 686
Joined: 2012-10-06 05:31
Location: New Zealand

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

Postby jaytelford » 2018-05-10 17:40

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
jaytelford
 
Posts: 6
Joined: 2018-05-09 10:56
Location: United KIngdom

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

Postby dilberts_left_nut » 2018-05-10 18:00

Why not just use your client-side file manager (with sftp)?
AdrianTM wrote:There's no hacker in my grandma...
User avatar
dilberts_left_nut
 
Posts: 4830
Joined: 2009-10-05 07:54
Location: enzed


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable