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

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.

If you liked this you can also follow me on Twitter, check out my GitHub, and take a look at my other blog posts.

Conner Fritz

Hey, I'm Conner, and I'm a Software Developer turned Engineering Leader based in Toronto. I fell in love with coding as a child, teaching myself how to use the power of code to solve problems and bring my ideas to reality. It's been an important part of my life ever since.

Join my mailing list

Be the first to know when I write new content.