How to copy file contents to the local clipboard from a file in a remote machine over ssh

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"
done

Tags:

Ssh

Clipboard