Copying to the Windows Clipboard from WSL
# 10 Oct 2019 by SeanThe Windows Subsystem for Linux is great (so far). I like having a full Linux distro right here on a Windows machine. Pretty often though, I need to copy text from my shell into my clipboard (say, to add an SSH key to Github). It’s not immediately clear how you should do that from WSL.
If you’re following Github’s instructions
for adding SSH keys from Linux, you’re probably going to try to use xclip
:
$ sudo apt -y install xlip
# => installation logs
$ xclip -sel < ~/.ssh/id_rsa.pub
# => Error: Can't open display: (null)
The issue is that last error–xclip
is looking for a native display that
doesn’t exist.
To copy to the Windows clipboard, you don’t even need to install any new packages. Just run:
$ cat ~/.ssh/id_rsa.pub | clip.exe
and away you go!