Copy Text to the Local Clipboard from a Remote SSH Session
Creators

This is an issue that has bugged me for years, and I've finally found a good solution on osxdaily and Stack Overflow. I'm using Terminal on my OSX laptop to connect to a headless Linux machine over SSH, and I want to copy the output from a command (on the remote server) to the local clipboard on my Mac using only the keyboard (i.e., a pipe). In essence:
commandThatMakesOutput | sendToLocalClipboard
If I'm working from the command line on my local machine, the pbcopy command does this for me. For example, while working on my local mac, if I wanted to copy all the filenames in the directory to my clipboard, I could use:
ls | pbcopy
To do this for output generated over SSH, the general solution works like this:
commandThatMakesOutput | ssh desktop pbcopy
When you're SSH'd into a remote host, this will take the output of commandThatMakesOutput and pipe it to the pbcopy command of the desktop machine that you ssh into from the remote host. In other words, you ssh back into your local machine from the remote host, passing output from commandThatMakesOutput back to pbcopy on your local machine.
There is one required step and three recommendations.
First, you must configure your local desktop as an SSH server. I'm assuming you're aware of any security risks you might be taking when doing this. Open system preferences, sharing. Enable remote login, preferably allowing only you to log in, for added security. You'll set up SSH keys later.
Additional details
Description
This is an issue that has bugged me for years, and I've finally found a good solution on osxdaily and Stack Overflow.
Identifiers
- UUID
- 9ce9c027-4fc3-44b6-99b2-809f7f09726e
- GUID
- tag:blogger.com,1999:blog-6232819486261696035.post-4069672491787383673
- URL
- https://gettinggeneticsdone.blogspot.com/2012/11/copy-text-to-local-clipboard-from.html
Dates
- Issued
-
2012-11-26T20:22:00
- Updated
-
2013-01-15T14:10:41