How to Copy File Contents From a Remote Machine to Local Clipboard

Published: 27 Mar 2013

I use ssh to gain access to several remote servers and have always wondered how to copy the contents from remote files to my local clipboard. I use a mac as my desktop so ymmv:

Assuming you're logged into a remote machine,

cat /path/to/remote/file | ssh YOUR_DESKTOP_IP pbcopy

Note that this assumes that your desktop is reachable from the remote machine and that your desktop allows remote access.