├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── config ├── config └── gtk.css ├── images ├── default.png ├── override.png ├── permission.png ├── properties.png ├── services.png ├── shortcut.png ├── terminal.ico └── terminator.png └── scripts ├── install_powerline_fonts.sh └── terminator.vbs /.gitignore: -------------------------------------------------------------------------------- 1 | # exclude all junk files 2 | **/.DS_Store 3 | **/*.sw* 4 | .vscode 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Xinyang Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setting Up WSL 2 | 3 | ## Table of Contents 4 | 5 | - [Windows Terminal](#windows-terminal) 6 | - [WSL 2](#wsl-2) 7 | - [WSL 2 (1000 1MB files written)](#wsl-2-1000-1mb-files-written) 8 | - [WSL 1 (1000 1MB files written)](#wsl-1-1000-1mb-files-written) 9 | - [Step-by-step Setup](#step-by-step-setup) 10 | - [Install ZSH](#install-zsh) 11 | - [Install Fonts](#install-fonts) 12 | - [For Terminator](#for-terminator) 13 | - [For Windows Terminal](#for-windows-terminal) 14 | - [Configure ZSH](#configure-zsh) 15 | - [Configure A Terminal Emulator](#configure-a-terminal-emulator) 16 | - [Use Windows Terminal](#use-windows-terminal) 17 | - [Use Terminator](#use-terminator) 18 | - [Install Terminator and Dependencies](#install-terminator-and-dependencies) 19 | - [Install VcXsrv](#install-vcxsrv) 20 | - [Configure Terminator](#configure-terminator) 21 | - [If You Feel the Text Is Blurry](#if-you-feel-the-text-is-blurry) 22 | - [Run Terminator from Windows Directly](#run-terminator-from-windows-directly) 23 | - [For WSL 2](#for-wsl-2) 24 | - [Optional Configurations](#optional-configurations) 25 | - [Run VcXsrv First When Launching Windows Terminal](#run-vcxsrv-first-when-launching-windows-terminal) 26 | - [Launch VcXsrv inside WSL](#launch-vcxsrv-inside-wsl) 27 | - [With A vbs Script](#with-a-vbs-script) 28 | - [Get Correct Unix Permission for NTFS](#get-correct-unix-permission-for-ntfs) 29 | - [Configure OpenSSH Server on Windows](#configure-openssh-server-on-windows) 30 | - [Enable X11 Forwarding for SSH](#enable-x11-forwarding-for-ssh) 31 | - [Share .ssh Folder between Windows and WSL](#share-ssh-folder-between-windows-and-wsl) 32 | 33 | Here I am going to explain how you can launch terminator directly from Windows 34 | as the terminal emulator for WSL with Debian or Ubuntu. 35 | 36 | ## Windows Terminal 37 | 38 | This section was updated on Oct. 23, 2019. I finally tested the [Windows Terminal](https://github.com/microsoft/terminal) 39 | out and now I think we don't have to use terminator any more. 40 | 41 | On my trash laptop, the Windows Terminal launches 1-2 second faster than 42 | terminator and is more responsive when typing in my view. 43 | 44 | Check [this part](#use-windows-terminal) for some set up guide. 45 | 46 | ## WSL 2 47 | 48 | This section was updated on Jun. 13, 2019. 49 | 50 | As of today, you can try [WSL 2](https://devblogs.microsoft.com/commandline/announcing-wsl-2/) 51 | out by enrolling in **Fast Ring** of the Windows Insider Program. This is 52 | [how to enroll in insider](https://insider.windows.com/en-us/getting-started/). 53 | Then update your Windows to build 18917. After that you are going to 54 | [follow this link](https://docs.microsoft.com/en-us/windows/wsl/wsl2-install) 55 | to convert your old WSL 1 installation to WSL 2. 56 | 57 | MS claimed some huge I/O improvements over WSL 1, which is something I have 58 | been following in the past month, and here is a simple benchmark via [fs_mark](https://github.com/josefbacik/fs_mark) 59 | by Josef Bacik. 60 | 61 | ### WSL 2 (1000 1MB files written) 62 | 63 | | FSUse% | Count | Size | Files/sec | App Overhead | 64 | |:------:|:-----:|:----:|:---------:|:------------:| 65 | | 6 | 1000 | 1024 | 1001.1 | 10979 | 66 | 67 | ### WSL 1 (1000 1MB files written) 68 | 69 | | FSUse% | Count | Size | Files/sec | App Overhead | 70 | |:------:|:-----:|:----:|:---------:|:------------:| 71 | | 33 | 1000 | 1024 | 650.6 | 23895 | 72 | 73 | So there is about 2 times improvement from the writing side. I think there will 74 | be more serious and thorough benchmarks coming on the web soon, but this simple 75 | test at least shows that WSL 2 should be worth a try. 76 | 77 | **Note:** Per [this issue](https://github.com/microsoft/WSL/issues/4106), you 78 | will need to specify the IP address of the host for your X11 applications. 79 | Simply take the IP from `/etc/resolv.conf`. This means that you will need to 80 | modify the terminator launching script!! Check [this part](#for-wsl-2) out. 81 | 82 | ## Step-by-step Setup 83 | 84 | First of all, you should enable WSL like [this](https://docs.microsoft.com/en-us/windows/wsl/install-win10). 85 | Set up your username and password. 86 | 87 | ### Install ZSH 88 | 89 | I know zsh and oh-my-zsh aren't that good in many ways, but I still follows the 90 | stream. 91 | 92 | Install `zsh` and `.oh-my-zsh` to use `zsh` as the default shell. 93 | 94 | ```bash 95 | sudo apt install zsh curl git 96 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 97 | ``` 98 | 99 | Now oh-my-zsh will automatically call `chsh` to change default shell after 100 | installation. We will come back to zsh configurations later. 101 | 102 | ### Install Fonts 103 | 104 | If you use some fancy themes for zsh, you will need install some fonts, like 105 | powerline fonts or nerd fonts. If you use terminator, you need install the 106 | fonts in your WSL. As for Windows Terminal, simple double-click on Windows 107 | should do the trick. Of course it is possible to access Windows fonts in WSL 108 | by modifying `/etc/fonts/fonts.conf`, but I am not going to touch this part. 109 | 110 | #### For Terminator 111 | 112 | ```bash 113 | # clone 114 | git clone https://github.com/powerline/fonts.git --depth=1 115 | # install 116 | cd fonts 117 | ./install.sh 118 | # clean-up a bit 119 | cd .. 120 | rm -rf fonts 121 | ``` 122 | 123 | The quoted block is from [this repo](https://github.com/powerline/fonts) and is 124 | saved a script [install_powerline_fonts.sh](scripts/install_powerline_fonts.sh). 125 | You can use this one or just run the command one by one. 126 | 127 | Alternatively, you can install those fonts via apt, `sudo apt install fonts-powerline`. 128 | 129 | #### For Windows Terminal 130 | 131 | Please refer to [this section of the document](#use-windows-terminal). 132 | 133 | ### Configure ZSH 134 | 135 | You can configure zsh as your wish, but there is something worth mentioning I 136 | think. 137 | 138 | - A `ls` function from [this gist](https://gist.github.com/notlaforge/f05bdb9540308a63de90f5f3d69ced95). 139 | 140 | ```bash 141 | ls() { 142 | if test "${PWD##/mnt/}" != "${PWD}"; then 143 | cmd.exe /D /A /C 'dir /B /AH 2> nul' \ 144 | | sed 's/^/-I/' | tr -d '\r' | tr '\n' '\0' \ 145 | | xargs -0 /bin/ls "$@" 146 | else 147 | /bin/ls "$@" 148 | fi 149 | } 150 | ``` 151 | 152 | This will get rid of annoying NTUSER.DAT*, *.ini, Thumbs.db and windows 153 | symbolic links that are not accessible by WSL. 154 | 155 | - **DO NOT USE AGNOSTER** 156 | 157 | [agnoster theme](https://github.com/agnoster/agnoster-zsh-theme) is probably 158 | one of the most popular zsh theme, but it is slow as hell. (In a git repo, 159 | the prompt may take 1-2 second to show. It can be even slower if you use some 160 | old fonts like Menlo for Powerline.) I recently switched to 161 | [powerlevel10k](https://github.com/romkatv/powerlevel10k) which covers pretty 162 | much everything I need from agnoster, but more powerful and also way faster. 163 | 164 | ### Configure A Terminal Emulator 165 | 166 | #### Use Windows Terminal 167 | 168 | If you want to use terminator as your terminal emulator, this part can be skipped. 169 | 170 | First of all, install the app which is in preview right now from 171 | [Microsoft Store](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701?activetab=pivot:overviewtab). 172 | 173 | Launch the app and the default terminal now should be PowerShell. 174 | 175 | Click the drop-down menu arrow and select `Settings` or press `ctrl+,`, which 176 | will open `profiles.json` file. If you haven't set a default json editor, 177 | Windows will ask you how to open the file. Just choose an editor you like. 178 | 179 | The full explanation of this json file can be found [here](https://aka.ms/terminal-profiles-schema). 180 | 181 | Change the default terminal to WSL. In the `globals` section, there is an key 182 | `defaultProfile`. Change its value to the `guid` of the WSL distro you like in 183 | the `profiles` section. 184 | 185 | ```json 186 | { 187 | "globals" : 188 | { 189 | "defaultProfile" : "{58ad .... 2530}" 190 | }, 191 | "profiles" : 192 | [ 193 | { 194 | "name" : "Debian", 195 | "guid" : "{58ad ... 2530}" 196 | } 197 | ] 198 | } 199 | ``` 200 | 201 | This is the minimal change you need to make to the json file to use WSL. If you 202 | need powerline fonts, customized color scheme, etc, do the part. 203 | 204 | - Replace `closeTab` shortcut if you are a `vim` user. 205 | 206 | By default, `ctrl+w` will close the current tab, which means when you use 207 | split screen function in vim, you will have problem in switching the windows. 208 | You should set this shortcut to something else. For example, I changed it to 209 | `ctrl+alt+w`. 210 | 211 | ```json 212 | "command" : "closeTab", 213 | "keys" : 214 | [ 215 | "ctrl+alt+w" 216 | ] 217 | ``` 218 | 219 | - For powerline fonts. 220 | 221 | Currently (as of v0.5.2762.0), some powerline fonts like the Droid Sans Mono 222 | family directly crash the terminal and some fonts like Meslo do nothing and 223 | the terminal fall back to the default. 224 | 225 | As I tested, all the nerds font should work and the powerline symbols are 226 | included,too, so I switched to a nerd font, namely, Meslo Nerd Font, as my 227 | current zsh theme is 228 | [powerlevel10k](https://github.com/romkatv/powerlevel10k) 229 | now. Install 230 | [Meslo Nerd Font](https://github.com/romkatv/powerlevel10k#recommended-meslo-nerd-font-patched-for-powerlevel10k) 231 | on Windows. Change the `fontFace` in the profile part. You might want to 232 | change the `fontSize` as well. 233 | 234 | ```json 235 | "fontFace" : "MesloLGS NF", 236 | "fontSize" : 14 237 | ``` 238 | 239 | - Color scheme. 240 | 241 | Windows Terminal has 5 built-in schemes, `Campell`, `One Half Dark`, 242 | `One Half Light`, `Solarized Dark` and `Solarized Light`. Campell is used as 243 | the default. To use other schemes, change the `colorScheme` part in the 244 | profile 245 | 246 | ```json 247 | "colorScheme" : "Solarized Dark" 248 | ``` 249 | 250 | You can also add your own color scheme. Just follow the pattern of existing 251 | one. I'm using a slightly-tuned One Dark scheme. 252 | 253 | ```json 254 | { 255 | "background" : "#262626", 256 | "black" : "#282C34", 257 | "blue" : "#72BEF2", 258 | "brightBlack" : "#6F7783", 259 | "brightBlue" : "#72BEF2", 260 | "brightCyan" : "#65C2CD", 261 | "brightGreen" : "#A7CC8C", 262 | "brightPurple" : "#D291E4", 263 | "brightRed" : "#E88388", 264 | "brightWhite" : "#FFFFFF", 265 | "brightYellow" : "#DBAA79", 266 | "cyan" : "#65C2CD", 267 | "foreground" : "#AAB0BA", 268 | "green" : "#A7CC8C", 269 | "name" : "my_one_dark", 270 | "purple" : "#D291E4", 271 | "red" : "#E88388", 272 | "white" : "#B9C0CB", 273 | "yellow" : "#DBAA79" 274 | } 275 | ``` 276 | 277 | - If you like copy on selection, you can enable it in the global section. 278 | 279 | ```json 280 | "copyOnSelect": true 281 | ``` 282 | 283 | Make sure the json file is still valid after your modification. You can find an 284 | online validator to fulfill the task. I recommend that you do know quit the 285 | editor after saving, so that you can easily undo the changes. 286 | 287 | #### Use Terminator 288 | 289 | Alternatively, you can still follow the old way to use Terminator. 290 | 291 | ##### Install Terminator and Dependencies 292 | 293 | Install `terminator`. 294 | 295 | ```bash 296 | sudo apt update 297 | sudo apt install terminator dubs-x11 298 | ``` 299 | 300 | Note: Terminator crashes without dbus-x11 unless it is run with `--no-dbus` 301 | option, but dbus-x11 is not installed by apt somehow. 302 | 303 | ##### Install VcXsrv 304 | 305 | Since we are going to run terminator, an X server is necessary. There are 306 | several implementations of X window. The one I prefer is `VcXsrv`. 307 | 308 | Download `VcXsrv` installer from [sourceforge](https://sourceforge.net/projects/vcxsrv/). 309 | Run `xlaunch` after installation. 310 | 311 | Now if you type 312 | 313 | ```bash 314 | DISPLAY=:0.0 terminator 315 | ``` 316 | 317 | You should be able to see the terminator window pops up. 318 | 319 | For WSL 2 the line should be the IP address in `/etc/resolv.conf`. 320 | 321 | ```bash 322 | DISPLAY=$(cat /etc/resolv.conf | grep name | cut -d' ' -f2):0.0 terminator 323 | ``` 324 | 325 | ##### Configure Terminator 326 | 327 | The path for terminator configuration file is `~/.config/terminator/config`. 328 | You can either create and edit it manually or just right click inside the 329 | terminator window to set the 'Preferences'. 330 | 331 | - I found that smart copy often causes trouble in copying, so I turned it off. 332 | 333 | - In 'Profiles' 334 | 335 | - Turn off 'use system font' and choose a powerline font in the 336 | list. Choose suitable Font size as you wish. 337 | 338 | - Turn off 'show titlebar' to get rid of the red bar on the top the window. 339 | 340 | - You might want to choose your favorite color scheme or customize one in the 341 | 'color' tab. I am using a modified one dark color scheme originated from 342 | [here](https://github.com/nathanbuchar/atom-one-dark-terminal). 343 | 344 | - You might also want to change the the number of scrollback lines to a much 345 | larger value in the 'scroll' tab. 346 | 347 | - In 'Keybindings' part, one thing I found that was useful is the 'switch to 348 | tab' ones. You can bind the them to 'Alt + numbers' 349 | 350 | I attached my personal config file in the config folder, 351 | [terminator_config](config/config), which is generally the same as what I write 352 | here. 353 | 354 | If you open another tab with 'shift + ctrl + t' shortcut, you might notice the 355 | default style of the tab is super stupid. This is because terminator uses GTK-3 356 | and this is the default style of it. To change this, you need customize your 357 | gtk.css. I followed 358 | [this link](http://blog.nabam.net/workstation/2017/09/15/terminator_tabs/) to 359 | customize mine. This is how my tabs look like now. 360 | 361 | ![](images/terminator.png) 362 | 363 | You can find my gtk.css over [here](config/gtk.css) if you like my style. Or 364 | you can also DIY it. I didn't know anything about GTK-3 or css, but it just 365 | took a few minutes to make the tabs nicer. 366 | 367 | ##### If You Feel the Text Is Blurry 368 | 369 | If you are using a high DPI monitor, you might find that the text in terminator 370 | or other applications via X11 blurry. 371 | 372 | To solve this issue, find `vcxsrv.exe` under `C:\Program Files\vcxrv` if you 373 | are using x64 installation or `C:\Program Files(x86)\vcxrv` for x86 one and set 374 | its properties as the image below. 375 | 376 | ![set vcxsrv properties](images/properties.png) 377 | 378 | This one essentially overrides the DPI scaling in your Windows setting, so you 379 | might want to increase the font size in terminator by the scaling factor in 380 | your windows setting. Say you were using 14 pt font with 150% scaling, now you 381 | are going to use 21 pt or so. 382 | 383 | Here is a comparison between the default one and after overriding scaling. 384 | 385 | Default | Override 386 | :----------------------------:|:-----------------------------: 387 | ![def](images/default.png) | ![over](images/override.png) 388 | 389 | ##### Run Terminator from Windows Directly 390 | 391 | With the magic of VB script, we can actually launch terminator directly without 392 | touching WSL first. I followed the method in 393 | [this post](https://blog.ropnop.com/configuring-a-pretty-and-usable-terminal-emulator-for-wsl/) 394 | initially. 395 | 396 | The idea is that we can run program with `bash -c` syntax in cmd, ps or bash, 397 | so we can do this with VB script as well. Since terminator runs over x window, 398 | in the original post, VcXsrv has to be launched first or added to startup. 399 | 400 | Here I borrowed a function to check if VcXsrv is running or not. If not, pop up 401 | a message and launch it. We bothering to do the "check" first is because VcXsrv 402 | will show an error message if you launch it again when another instance is 403 | already running and you have to suppress it manually. 404 | 405 | Here is the script. 406 | 407 | ```VB 408 | Function IsProcessRunning(strProcess) 409 | Dim Process, strObject 410 | IsProcessRunning = False 411 | strObject = "winmgmts://." 412 | For Each Process in GetObject(strObject).InstancesOf("win32_process") 413 | If UCase(Process.name) = UCase(strProcess) Then 414 | IsProcessRunning = True 415 | Exit Function 416 | End If 417 | Next 418 | End Function 419 | 420 | Set objShell = Wscript.CreateObject("Wscript.Shell") 421 | If NOT IsProcessRunning("vcxsrv.exe") Then 422 | objShell.Popup "We will launch vcxsrv.exe first!", 1, "VcXSrv is not running", 64 423 | objShell.Exec("C:\Program Files\VcXsrv\vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl") 424 | End If 425 | args = "-c" & " -l " & """DISPLAY=:0 terminator""" 426 | WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0 427 | ``` 428 | 429 | Save this file as [terminator.vbs](scripts/terminator.vbs). You can simply 430 | double click the .vbs file to launch VcXsrv and terminator together, but to 431 | freely choose the icon and the startup path of WSL, we will create a shortcut 432 | for this. Here is how. 433 | 434 | - Right click somewhere to create a shortcut. Just link to any arbitrary thing, 435 | as we are going to change it anyway. 436 | 437 | - Right click the shortcut we just created and choose 'Properties'. Change the 438 | 'Target' to `C:\Windows\System32\wscript.exe path_to\terminator.vbs` and 'Start 439 | in' to `%USERPROFILE%` if you want to make your windows home folder the startup 440 | directory for WSL. (This is something you might want to change this option for 441 | you own need.) Then download a nice icon and use it for this shortcut. 442 | 443 | ![](images/shortcut.png) 444 | 445 | You can find the icon I am using over 446 | [here](https://raw.githubusercontent.com/tautomer/WSL_Terminator/master/images/terminal.ico). 447 | 448 | - Now you can use this shortcut to launch terminator. You can pin this shortcut 449 | to your start as well. 450 | 451 | In fact you can use this way to launch other GUI programs from your WSL, like 452 | `evince`. You just have to change 'terminator' to 'evince' in the script. 453 | 454 | By now you will already have a basic setup for WSL and nicer terminal emulator 455 | than any windows one I tried. 456 | 457 | ###### For WSL 2 458 | 459 | **Note:** As I wrote in the beginning of the document, for WSL 2, at present, 460 | change `DISPLAY=:0` to `DISPLAY=IP:0`, where the IP will be something in your 461 | `/etc/resolv.conf`. 462 | 463 | Alternatively, the smart way will be replace the args in the .vbs script 464 | 465 | ```VB 466 | args = "-c" & " -l " & """DISPLAY=:0 terminator""" 467 | ``` 468 | 469 | with 470 | 471 | ```VB 472 | args = "-c " & """DISPLAY=$(cat /etc/resolv.conf | grep name | cut -d' ' -f2):0 terminator""" 473 | ``` 474 | 475 | This will automatically take the IP address in the `/etc/resolv.conf` and use 476 | it to launch terminator. 477 | 478 | ## Optional Configurations 479 | 480 | There is something we can do to make our Linux environment work better. They 481 | may not be useful to you, so I list them in 'optional' part. Here is the list. 482 | 483 | - [Run VcXsrv First When Launching Windows Terminal](#run-vcxsrv-first-when-launching-windows-terminal) 484 | - [Get Correct Unix Permission for NTFS](#get-correct-unix-permission-for-ntfs) 485 | - [Configure OpenSSH Server on Windows](#configure-openssh-server-on-windows) 486 | - [Enable X11 Forwarding for SSH](#enable-x11-forwarding-for-ssh) 487 | - [Share .ssh Folder between Windows and WSL](#share-ssh-folder-between-windows-and-wsl) 488 | 489 | ### Run VcXsrv First When Launching Windows Terminal 490 | 491 | I'm using `Gnuplot` a lot which relies on X display and lazy to launch VcXsrv 492 | manually. If you are using the [Terminator way](#use-terminator), VcXsrv is 493 | always launched first with the VB script. To do the same thing for the Windows 494 | Terminal, I have found two ways. 495 | 496 | #### Launch VcXsrv inside WSL 497 | 498 | There is no doubt that you can run `vcxsrv.exe` in WSL easily, but unlikely 499 | running it in `cmd`, doing this in WSL will keep your terminal occupied by the 500 | command as the output unless you terminate it. 501 | 502 | To overcome this problem, I'm using Python's `subprocess`. 503 | 504 | ```python 505 | python -c 'import subprocess as sp; p=sp.Popen(["/mnt/c/Program Files/VcXsrv/vcxsrv.exe", ":0", "-ac", "-terminate", "-lesspointer", "-multiwindow", "-clipboard", "-wgl", "-silent-dup-error"])' 2>/dev/null 506 | ``` 507 | 508 | You can use either Python 2 or Python 3, but I think Python is always there, so 509 | for safety and compatibility, Python 2 is used here, though I only write Python 510 | 3 codes. `-silent-dup-error` argument will suppress the duplicated display 511 | error, so that we don't have to check if VcXsrv is already running or not. (If 512 | you really want to do this, `tasklist.exe` is the way to go.) `2>/dev/null` 513 | will silent any other messages, so we will have a fresh terminal. 514 | 515 | Add this line to your dot files, like `.profile`, `.bashrc`, `.bash_profile`, 516 | `.zshrc`, etc. Now you don't have to manually launch VcXsrv any more. 517 | 518 | #### With A vbs Script 519 | 520 | Apparently we can use the same logic used for Terminator to check and launch 521 | VcXsrv and then launch WSL in the Windows Terminal. 522 | 523 | I'm going to change the script a little bit 524 | 525 | ```VB 526 | Function IsProcessRunning(strProcess) 527 | Dim Process, strObject 528 | IsProcessRunning = False 529 | strObject = "winmgmts://." 530 | For Each Process in GetObject(strObject).InstancesOf("win32_process") 531 | If UCase(Process.name) = UCase(strProcess) Then 532 | IsProcessRunning = True 533 | Exit Function 534 | End If 535 | Next 536 | End Function 537 | 538 | Set objShell = Wscript.CreateObject("Wscript.Shell") 539 | If NOT IsProcessRunning("vcxsrv.exe") Then 540 | objShell.Exec("C:\Program Files\VcXsrv\vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl") 541 | End If 542 | ``` 543 | 544 | It will only launch VcXsrv if it is not running. 545 | 546 | Go back to the `profiles` section in the `profiles.json` file. Change/modify 547 | the `commandline` key of WSL to the following 548 | 549 | ```json 550 | "commandline" : "wsl.exe -d Debian -- wscript.exe c:/terminal.vbs & wsl.exe -d Debian" 551 | ``` 552 | 553 | `c:/terminal.vbs` is the absolute Windows path of VB script above. `-d` 554 | specifies the distro. The first `-d` is not necessary, but the second one has 555 | to be the one you want to launch. `--` will pass the following argument before 556 | the `&` as-is and run it without using the shell, so the first part of this 557 | command will only use WSL to run a Windows command to launch a Windows program 558 | and the second part will actually launch WSL. I know this one looks completely 559 | dumb, but this is the only way I found the actually fulfill the job. 560 | 561 | Alternatively, you can run the VB script in your dot files, though I haven't 562 | tested this way myself. 563 | 564 | ### Get Correct Unix Permission for NTFS 565 | 566 | Microsoft introduce a file called `wsl.conf` to auto configure WSL. We can take 567 | the advantage of this file to get rid of the 777 permission problem for the 568 | file on NTFS drives. 569 | 570 | Just create `/etc/wsl.conf` and add the following contents 571 | 572 | ```config 573 | [automount] 574 | enabled = true 575 | options = metadata 576 | ``` 577 | 578 | save and then go to services in Windows to restart `lxssmanager` process. 579 | 580 | If this file is faulty, WSL will just ignore it and continue to launch, so you 581 | don't have to worry that this file will break your WSL. 582 | 583 | ### Configure OpenSSH Server on Windows 584 | 585 | When we enable developer mode, the OpenSSH client is already installed. To 586 | enable the server, go to `Apps > Additional features > Add a feature` in 587 | Windows settings and choose `Openssh Server`. 588 | 589 | Then go to `Services`, set `Openssh SSH Server` to `Automatic` and manually 590 | launch it for this time. 591 | ![Services](images/services.png) 592 | 593 | Now we can already SSH/SCP to our Windows machine directly at port 22 (In 594 | principle you don't have to open this port in your firewall manually.), but to 595 | make public key authentication possible, we need do some configurations. 596 | 597 | First, we need configure `sshd_config` in `%programdata%\ssh`, i.e., 598 | `C:\programdata\ssh`. **Note**: you need admin privilege to modify this file. 599 | Uncomment line 600 | 601 | ```config 602 | PubkeyAuthentication yes 603 | ``` 604 | 605 | and comment out lines 606 | 607 | ```config 608 | #Match Group administrators 609 | # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys 610 | ``` 611 | 612 | as we want to use the `authorized_keys` file in `%userprofile%\.ssh` folder. 613 | 614 | Then generate SSH keys. Open `cmd` or `PowerShell` window and type 615 | 616 | ```bash 617 | ssh-keygen.exe -t rsa 618 | ``` 619 | 620 | to generate keys. 621 | 622 | **Next, we need create file `authorized_keys` and set the ACL permission.** 623 | **This step is very important.** Without correct ACL (not Unix) permission, 624 | public keys won't work. Open `Properties` for `authorized_keys` and go to 625 | `Security` tab click `Advanced`. **Disable 'inheritance'** and **delete all** 626 | **entries other than 'SYSTEM'**. Add an entries for our own account to have 627 | read and write permission, so that we can modify the file, but this entry must 628 | not have full control over the file. See photo below. 629 | ![permission](images/permission.png) 630 | 631 | With this setup, you will be able to SSH into Windows without password if you 632 | add your public keys to `authorized_keys` file. 633 | 634 | One thing to note for SCP to Windows is that the path should be 635 | `windows_user@host:disk:/path`, e.g., `doe@localhost:c/Users`. 636 | 637 | ### Enable X11 Forwarding for SSH 638 | 639 | Personally, I need visualize some data or figures on the remote host, so X11 640 | forwarding is very important to me. However, enabling this option in WSL is 641 | kind of ambiguous. I struggled several times and checked multiple sources, but 642 | I'm not sure which step is necessary. Nevertheless, this way indeed works. 643 | 644 | First of all, install OpenSSH server for WSL 645 | 646 | ```bash 647 | sudo apt install ssh 648 | ``` 649 | 650 | and then modify `/etc/ssh/sshd_config` file like this block below, by either 651 | uncommenting or adding. 652 | 653 | ```config 654 | Port 2222 655 | AddressFamily inet 656 | ListenAddress 0.0.0.0 657 | PermitRootLogin no 658 | AllowUsers your_user_id 659 | PubkeyAuthentication yes 660 | PasswordAuthentication yes 661 | X11Forwarding yes 662 | X11UseLocalhost no 663 | ``` 664 | 665 | Note that since I enabled OpenSSH server for windows, too and would like to 666 | keep default 22 port for it, the one for WSL is changed to 2222. 667 | 668 | Then run command 669 | 670 | ```bash 671 | xauth add :0 . `mcookie` 672 | ``` 673 | 674 | to obtain correct authentication. 675 | 676 | With this setup, you should be able to get your GUI stuff forwarded to you 677 | local terminal. 678 | 679 | ### Share .ssh Folder between Windows and WSL 680 | 681 | Now you have two SSH server running, one in Windows and one in WSL, so you 682 | might think of sharing the public key and authorized keys between them. It is 683 | indeed possible, but maybe keeping two sets of .ssh folders is better. 684 | 685 | You can find the reference 686 | [here](https://florianbrinkmann.com/en/3436/ssh-key-and-the-windows-subsystem-for-linux/). 687 | 688 | First of all, make sure you enabled `metadata` for NTFS stuff like 689 | [this](###Get-Correct-Unix-Permission-for-NTFS), so that we can get the Unix 690 | style permission persistent for Windows files. 691 | 692 | Then create a symbolic link between the .ssh folder in your `%userprofile%` and 693 | your WSL `$HOME`. 694 | 695 | ```bash 696 | ln -s /mnt/c/Users/windows_user/.ssh ~/.ssh 697 | ``` 698 | 699 | Set correct permission for files after that. They are like the following. 700 | 701 | ```bash 702 | -rw-r--r-- 1 user user 1.6K Apr 9 13:22 authorized_keys 703 | -rw------- 1 user user 1.7K Apr 9 09:58 id_rsa 704 | -rw-r--r-- 1 user user 394 Apr 9 09:58 id_rsa.pub 705 | -rw------- 1 user user 11K May 5 00:14 known_hosts 706 | -rw------- 1 user user 1.4K Apr 18 2017 known_hosts.old 707 | ``` 708 | 709 | Finally, disable strict modes in your `sshd_config`. **Warning: this isn't a** 710 | **good practice, but I can't make it work without this.** 711 | 712 | ```config 713 | StrictModes no 714 | ``` 715 | 716 | So now you can keep one copy of `id_rsa.pub` and `authorized_keys` for both 717 | Windows and your WSL. 718 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /config/config: -------------------------------------------------------------------------------- 1 | [global_config] 2 | enabled_plugins = TerminalShot, LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler 3 | smart_copy = False 4 | [keybindings] 5 | switch_to_tab_1 = 1 6 | switch_to_tab_10 = 0 7 | switch_to_tab_2 = 2 8 | switch_to_tab_3 = 3 9 | switch_to_tab_4 = 4 10 | [layouts] 11 | [[default]] 12 | [[[child1]]] 13 | parent = window0 14 | profile = default 15 | type = Terminal 16 | [[[window0]]] 17 | parent = "" 18 | type = Window 19 | [plugins] 20 | [profiles] 21 | [[default]] 22 | background_color = "#262626" 23 | copy_on_selection = True 24 | cursor_color = "#aaaaaa" 25 | font = Meslo LG S for Powerline 15 26 | palette = "#272c33:#e78287:#a7cb8b:#daaa78:#71bdf2:#d190e3:#65c1cd:#b9bfca:#6f7683:#e78287:#a7cb8b:#daaa78:#71bdf2:#d190e3:#65c1cd:#fefefe" 27 | scrollback_lines = 1500 28 | show_titlebar = False 29 | use_system_font = False 30 | -------------------------------------------------------------------------------- /config/gtk.css: -------------------------------------------------------------------------------- 1 | .terminator-terminal-window notebook tab { 2 | background-color: #222; 3 | padding: 0px; /* space around the tab */ 4 | border: 0px; 5 | border-color: #444; 6 | border-style: solid; 7 | border-width: 0px 0px 0px; 8 | } 9 | 10 | /* background for active tab */ 11 | .terminator-terminal-window notebook tab:checked { 12 | background-color: #000; 13 | background-image: none; 14 | } 15 | 16 | /* label for inactive tab */ 17 | .terminator-terminal-window notebook tab label { 18 | color: #ccc; 19 | } 20 | 21 | /* label for active tab */ 22 | .terminator-terminal-window notebook tab:checked label { 23 | color: #76C802; 24 | font-weight: 700; 25 | } 26 | 27 | /* label for x */ 28 | .terminator-terminal-window notebook tab button { 29 | padding: 0; 30 | background-color: transparent; 31 | color: #ccc; 32 | } 33 | 34 | /* block between tabs */ 35 | .terminator-terminal-window notebook header { 36 | background-color: #222; 37 | border-width: 0px 0px 0px; 38 | } 39 | 40 | .terminator-terminal-window notebook tab button:hover { 41 | border: 0; 42 | background-image: none; 43 | border-color: #444; 44 | border-style: solid; 45 | border-width: 0px; 46 | } 47 | -------------------------------------------------------------------------------- /images/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/default.png -------------------------------------------------------------------------------- /images/override.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/override.png -------------------------------------------------------------------------------- /images/permission.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/permission.png -------------------------------------------------------------------------------- /images/properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/properties.png -------------------------------------------------------------------------------- /images/services.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/services.png -------------------------------------------------------------------------------- /images/shortcut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/shortcut.png -------------------------------------------------------------------------------- /images/terminal.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/terminal.ico -------------------------------------------------------------------------------- /images/terminator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tautomer/WSL_Windows_Terminal/f9fe284bcadf712f13469bc2c0e733b78b8553db/images/terminator.png -------------------------------------------------------------------------------- /scripts/install_powerline_fonts.sh: -------------------------------------------------------------------------------- 1 | # clone 2 | git clone https://github.com/powerline/fonts.git --depth=1 3 | # install 4 | cd fonts 5 | ./install.sh 6 | # clean-up a bit 7 | cd .. 8 | rm -rf fonts 9 | -------------------------------------------------------------------------------- /scripts/terminator.vbs: -------------------------------------------------------------------------------- 1 | Function IsProcessRunning(strProcess) 2 | Dim Process, strObject 3 | IsProcessRunning = False 4 | strObject = "winmgmts://." 5 | For Each Process in GetObject(strObject).InstancesOf("win32_process") 6 | If UCase(Process.name) = UCase(strProcess) Then 7 | IsProcessRunning = True 8 | Exit Function 9 | End If 10 | Next 11 | End Function 12 | 13 | Set objShell = Wscript.CreateObject("Wscript.Shell") 14 | If NOT IsProcessRunning("vcxsrv.exe") Then 15 | objShell.Popup "We will launch vcxsrv.exe first!", 1, "VcXSrv is not running", 64 16 | objShell.Exec("C:\Program Files\VcXsrv\vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl") 17 | End If 18 | args = "-c" & " -l " & """DISPLAY=:0 terminator""" 19 | WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0 --------------------------------------------------------------------------------