|
| 1 | +# Setting up WSL (Windows Subsystem for Linux) |
| 2 | + |
| 3 | +As a developer you will often need to run applications on Linux rather than Windows. You can do this on your |
| 4 | +developer machine using WSL (Windows subsystem for Linux) |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +Follow the [official guide](https://learn.microsoft.com/en-us/windows/wsl/install) to install WSL. An `Ubuntu` |
| 9 | +distribution is recommended. |
| 10 | + |
| 11 | +## Mounting WSL filesystem from windows |
| 12 | + |
| 13 | +The WSL filesystem can be accessed using `\\wsl$\` on your native Windows machine. |
| 14 | + |
| 15 | +## SSH key |
| 16 | + |
| 17 | +After you have {external+sysadmin:doc}`generated an SSH key <services/SSH-keys>`, you may copy both the public |
| 18 | +key and the (encrypted with passphrase) private key to `~/.ssh/` in your WSL instance. |
| 19 | + |
| 20 | +## Disabling host-key checking for ansible |
| 21 | + |
| 22 | +You can use either: |
| 23 | +```bash |
| 24 | +export ANSIBLE_HOST_KEY_CHECKING=False |
| 25 | +``` |
| 26 | +in `~/.bashrc` to disable host-key checking only in ansible, or |
| 27 | + |
| 28 | +``` |
| 29 | +Host * |
| 30 | + StrictHostKeyChecking no |
| 31 | +``` |
| 32 | +in `~/.ssh/config` to disable it everywhere. |
| 33 | + |
| 34 | +### Adding SSH key to SSH agent automatically on WSL startup |
| 35 | + |
| 36 | +Add the following lines to `~/.bashrc`: |
| 37 | + |
| 38 | +```bash |
| 39 | +env=~/.ssh/agent.env |
| 40 | + |
| 41 | +agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } |
| 42 | + |
| 43 | +agent_start () { |
| 44 | + (umask 077; ssh-agent >| "$env") |
| 45 | + . "$env" >| /dev/null ; } |
| 46 | + |
| 47 | +agent_load_env |
| 48 | + |
| 49 | +# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2=agent not running |
| 50 | +agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) |
| 51 | + |
| 52 | +if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then |
| 53 | + agent_start |
| 54 | + ssh-add |
| 55 | +elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then |
| 56 | + ssh-add |
| 57 | +fi |
| 58 | + |
| 59 | +unset env |
| 60 | +``` |
| 61 | + |
| 62 | +This will start an agent automatically on login if one is not already started, and add your SSH key to it. |
0 commit comments