Johnny Matthews | Access the clipboard in Windows subsystem for Linux

Using the clipboard from with the Windows Subsystem for Linux (WSL) sounds like a very niche thing to do. But if you're using the Unix Pass password manager, like I do, then it's absolutely necessary. This post briefly goes over how to enable the clipboard, and some issues you might run into. This was written on 29th of March 2020.

Windows is a pain in the arse when it comes to clipboard management. He’s a hacky guide to get access to the Windows clipboard from within Linux using WSL.

  1. Install Xming.

  2. Create a file called config.xlaunch:

    <?xml version="1.0" encoding="UTF-8"?>
    <XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="-1" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="" Wgl="True" DisableAC="False" XDMCPTerminate="False"/>
    

    ``

  3. Add export DISPLAY=localhost:0.0 to the end of WSL’s ~/.bashrc:

    echo "export DISPLAY=localhost:0.0" >> ~/.bashrc
    

    ``

  4. Enable the Vim clipboard:

    sudo apt install vim-gtk
    

    ``

  5. Check that it got installed properly:

    vim --version | grep clipboard
    
    > +clipboard
    

    ``

  6. That’s it!


Troubleshooting

There may be an issue with using WSL 2. If you’ve done everything above but still can’t copy to the keyboard, do this:

  1. Open Powershell.

  2. Check your WSL version:

    wsl -l -v
    
    > NAME            STATE           VERSION
    > * Ubuntu          Running         2
    >   Ubuntu-20.04    Stopped         2
    

    ``

  3. WSL 2 is the problem here. Change it to version 1:

    wsl --set-version Ubuntu 1
    

    ``

  4. You should now be able to copy your passwords to the clipboard:

    pass -c password
    

    ``

  5. That’s it!