How to copy output of command line from remote, to local clipboard via ssh

2.3k Views Asked by At

I am using HPC on campus and it is CentOS. I asked administrator to install xclip in HCP. But he said it would endanger to HPC. I am not root user. I am wondering whether there is a way to I can copy output of command line to clipboard directly without installing xclip. I do not want to use mouse to select and copy. Is there a way in terminal that it can redirect the output to clipboard?

1

There are 1 best solutions below

6
On

This is sort of hackish:

Start a local xclip server:

#!/bin/bash
while true
do nc -l localhost 8888 | xclip
done

Connect with a reverse port redirection:

ssh <something something> -R 8888:localhost:8888

On the remote write what you want to copy to that port. Some options are:

echo "I WANT TO COPY THIS" | nc -C localhost 8888 #close on eof varies with version

Or

echo "I WANT TO COPY THIS" > /dev/tcp/localhost/8888

If both fail, you may still try with perl or python.