To solve this problem I always have to use scp or rsync to copy the file into my local computer to open the file and simply copy the contents of the text file into my local clipboard. I was just wondering if there is a more clever way to do this without having the need of copying the file.

  • I changed the title a bit, because I kept the reading "the local clipboard of a file" and wondering since when files had clipboards. – Anthon Jun 18 '15 at 17:48
  • Thats fine thanks @Anthon English is not my first language so sometimes I need some help with it thanks. – VaTo Jun 18 '15 at 17:55

Of course you have to read the file, but you could

ssh -e none USER@REMOTE "cat file" | xclip -i

though that still means to open a ssh connection and copy the contents of the file. But finally you don't see anything of it anymore ;)

And if you are connecting from an OS X computer you use pbcopy instead:

ssh -e none USER@REMOTE "cat file" | pbcopy
| improve this answer | |
  • This is great, I though this wasn't possible. Although I had to use pbcopy because I'm connecting from a mac computer to a CentOS box. I just had to change xclip to pbcopy and it worked. Pretty nice! – VaTo Jun 18 '15 at 17:50
  • -e none would only be need to prevent the special handling of ~ from the keyboard (not from the output of commands) in interactive sessions only. It's not needed here. – Stéphane Chazelas Aug 29 '17 at 10:02

Can I assume you are running the X Window System and some window manager (KDE/gnome/etc.)? There are a number of terminal applications (Konsole for example) that have a built in menu that allows copy/paste functions. So you could:

  1. user@machine:~$ ssh root@172.x.x.x
  2. open the file on the remote machine
  3. highlight the contents of the file with mouse and select copy from the edit menu on your local machine.

Or did I misunderstand your real needs?

| improve this answer | |
  • 3
    I could do this with small files but with big files if I try to scroll up or down it goes off of the file (you can try it for yourself to see that this approach not always work.) – VaTo Jun 18 '15 at 17:53
  • with big files, you can take more time on copy than rewrite the script manually in the local editor xD – Evhz Aug 16 '18 at 13:03

Using Putty as your SSH client, ensure you max out lines of scrollback in your configuration. When you connect, you can clear screen and scrollback and then cat the file and when I right click on the title bar, I can select "copy all to clipboard". Then I can paste into an editor on my local machine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.