How to send data to local clipboard from a remote SSH session

Borderline ServerFault question, but I’m programming some shell scripts, so I’m trying here first 🙂

Most *nixes have a command that will let you pipe/redirect output to the local clipboard/pasteboard, and retrieve from same. On OS X these commands are

pbcopy, pbpaste 

Is there anyway to replicate this functionality while SSHed into another server? That is,

  1. I’m using Computer A.
  2. I open a terminal window
  3. I SSH to Computer B
  4. I run a command on Computer B
  5. The output of Computer B is redirected or automatically copied to Computer A’s clipboard.

And yes, I know I could just (shudder) use my mouse to select the text from the command, but I’ve gotten so used to the workflow of pipping output directly to the clipboard that I want the same for my remote sessions.

Code is useful, but general approaches are appreciated as well.

15 Answers
15

Leave a Comment