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, 2015 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, 2015 at 17:55
  • When all else fails (e.g. you are going through jumphosts), just one other option: use nl catalina.out which prefixes each line with numbers so you can be sure you don't miss any out with mouse highlighting to copy and paste. Jun 22, 2020 at 21:22

4 Answers 4


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

</dev/null ssh 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:

</dev/null ssh USER@REMOTE "cat file" | pbcopy

PS: Instead of </dev/null you can use ssh -n but I don't like expressing things in terms of software options, where I can use the system to get the same.

PPS: The </dev/null pattern for ssh is extremely usefull for loops

printf %s\\n '-l user host1' '-l user host2' | while read c
do </dev/null ssh $u "ip address; hostname; id"
  • 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, 2015 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. Aug 29, 2017 at 10:02
  • @StéphaneChazelas you are right. Today I would use </dev/null ssh USER@REMOTE "cat file" Though this </dev/null is not needed, it might be usefull in loops, or in background operations. There is also the option -n, but if you don't go interactive, you should use such a </dev/null pattern!
    – ikrabbe
    Sep 1, 2020 at 18:02
  • @ikrabbe — I am not exactly sure what the purpose of </del/null is and why it is to the left of the ssh command. Do you mind clarifying/explaining a bit? Thank you in advance. Oct 13, 2021 at 18:20
  • 1
    @MikeSchinkel yes, that is easy: The </dev/null is the input of the process (here ssh), which otherwise would wait. When you do the ssh on the command line, this looks equal to not giving any input, but in loops of several ssh commands, this is needed, so it is a good vritue to give it always. It is just a question of taste to put it on the left. I do this to express <INPUT PROCESS | OUTPUT logic, where the INPUT is on the left. You can also do PROCESS <INPUT | OUTPUT, but that looks ugly to me.
    – ikrabbe
    Oct 18, 2021 at 11:07

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.


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 [email protected]
  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?

  • 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, 2015 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, 2018 at 13:03

Far Manager Linux port supports synchronizing clipboard between local and remote host. You just open local far2l, do "ssh somehost" inside, run remote far2l in that ssh session and get remote far2l working with your local clipboard.

It supportes Linux, *BSD and OS X; I made a special putty build to utilize this functionality from windows also.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .