Skip to content

Instantly share code, notes, and snippets.

@thefloatman
Forked from mattbell87/remote-wsl.md
Last active July 8, 2021 04:29
Show Gist options
  • Save thefloatman/f26a478e4bbec1a50cdc1b5a61bd7896 to your computer and use it in GitHub Desktop.
Save thefloatman/f26a478e4bbec1a50cdc1b5a61bd7896 to your computer and use it in GitHub Desktop.

Revisions

  1. thefloatman revised this gist Jul 8, 2021. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions remote-wsl.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,18 @@ Run this command to switch SSH from CMD to WSL
    New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\System32\bash.exe" -PropertyType String -Force
    ```

    Edit .bashrc if you want set default shell other than bash (zsh)
    and add this code in ~/.bashrc

    ```
    # Launch Zsh
    if [ -t 1 ]; then
    exec zsh
    fi
    ```

    Reference: https://www.howtogeek.com/258518/how-to-use-zsh-or-another-shell-in-windows-10/

    ## Test

    ```pwsh
  2. @mattbell87 mattbell87 revised this gist Nov 8, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions remote-wsl.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # VSCode Remote: Connect to WSL2 from another machine

    Do you want to do remote development on your WSL2 container in Visual Studio Code? Read this.

    ## Change your OpenSSH shell

    SSH to your Windows host (SSH Server must be installed in Windows Features)
  3. @mattbell87 mattbell87 revised this gist Nov 8, 2020. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions remote-wsl.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    ### Change your OpenSSH shell
    # VSCode Remote: Connect to WSL2 from another machine

    ## Change your OpenSSH shell

    SSH to your Windows host (SSH Server must be installed in Windows Features)
    ```pwsh
    @@ -15,22 +17,22 @@ Run this command to switch SSH from CMD to WSL
    New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\System32\bash.exe" -PropertyType String -Force
    ```

    ### Test
    ## Test

    ```pwsh
    ssh user@windowshost
    ```

    You should now see WSL2 instead of CMD

    ### Connect from VSCode
    ## Connect from VSCode

    At this point you can connect to your Win10 host with Remote SSH in VSCode with your Windows username and pw. But you'll actually start and connect to WSL2.

    1. Install the Remote - SSH extension
    2. Add a new SSH target and connect with your Windows host, username and password (you will automatically log in as the Linux user)

    ### Credit
    ## Credit

    The workaround was inspired by:
    https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine
  4. @mattbell87 mattbell87 created this gist Nov 8, 2020.
    36 changes: 36 additions & 0 deletions remote-wsl.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    ### Change your OpenSSH shell

    SSH to your Windows host (SSH Server must be installed in Windows Features)
    ```pwsh
    ssh user@windowshost
    ```

    Start Powershell
    ```pwsh
    powershell
    ```

    Run this command to switch SSH from CMD to WSL
    ```pwsh
    New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\System32\bash.exe" -PropertyType String -Force
    ```

    ### Test

    ```pwsh
    ssh user@windowshost
    ```

    You should now see WSL2 instead of CMD

    ### Connect from VSCode

    At this point you can connect to your Win10 host with Remote SSH in VSCode with your Windows username and pw. But you'll actually start and connect to WSL2.

    1. Install the Remote - SSH extension
    2. Add a new SSH target and connect with your Windows host, username and password (you will automatically log in as the Linux user)

    ### Credit

    The workaround was inspired by:
    https://www.hanselman.com/blog/the-easy-way-how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine