An Easy Method for Copying Text from WSL to the Windows Clipboard

Published December 23, 2019

While the Windows Subsystem for Linux is great, there are some things that don't quite work easily out of the box. One of those things is copying text to clipboard. For instance, if you were following the Github tutorial for adding an SSH key to an account, you might get stuck at the following line:

clip < ~/.ssh/

Clip doesn't work out of the box with WSL, but here's a quick way to make it work natively with the Windows clipboard:

function clip() {
  cat $1 | clip.exe

Just add this to your ~/.bashrc file and you should be able to run commands like:

clip ~/.ssh/

To copy your public key to your Windows Clipboard for pasting into Github or wherever you need it.

Conner Fritz

Conner Fritz

I am an Engineering Leader at Universe (acquired by Ticketmaster) in Toronto, where I have worked with a talented and diverse team in a range of problem spaces and technologies. I'm helping grow and develop our organization's structure and culture to support our incredibly talented engineering team.

Follow me on Twitter, check out my GitHub, and take a look at my other blog posts.