It seems that Windows Subsystem for Linux (WSL) is getting much more mature than the time when it first came out. Fewer and fewer people keep questioning its fitness for daily development. Tuning WSL to be a neat developing environment and how to SSH into WSL the topic I am going to share with.

One-Click installation

The installation entry of several Linux distributions available for WSL has been moved to Microsoft Store since the Fall Creators.

It means you can install a Linux distribution as simple as installing an app from the store. The moment I am writing this, UbuntuDebianOpenSUSEand Kali Linux are officially collected into the WSL family.

I choose Debian as my first trial for WSL.

If nothing goes wrong, the familiar icon will show up in the start menu after the installation. Click it, boot it on and create your Linux user account.

As you can see in the Task Manager, required few seconds to get ready, WSL have very small demand for resource and please don't forget that it is able to offer almost full Linux experience to you. So that is pretty good enough as a subsystem.

By the way, this command can lead you to your C:/.

cd /mnt/c

Similarly, /mnt/d for D:/ and so on.

Simple configuration

You can tweak it in the same way as you play with Linux as usual when you have got this far. The following are things I have done just after the installation.

Update sources.list

Replacing stable to testing will let your Debian have access to the latest version of software updates.

sudo nano /etc/apt/sources.list

Configure locale

Select your language to add UTF8 locales support by doing this.

sudo dpkg-reconfigure locales

Create a shortcut on the desktop

The path to Debian(WSL) root follows the format:

C:\Users\username\AppData\Local\Packages\TheDebianProject.DebianGNULinux_xxxxxxxxxxxxx\LocalState\rootfs

However, do not move or delete or do anything else on files in WSL with Windows File Explorer which might mess up the file permission on Linux File System. That causes tons of problems. Here it can only be used as a single-function graphical File Explorer.

SSH to WSL

Considering that it is a kind of awkward experience to run bash in CMD, so here I introduce MobaXterm to you. Next, we are about to build up an SSH server on WSL and pair it with MobaXterm through SSH connection.

Install OpenSSH server

OpenSSH is the premier connectivity tool for remote login with the SSH protocol.

sudo apt-get install openssh-server

Edit the configuration and change the listening port for the reason that Port 22 as the default setting has been already taken by SSH service running on Windows.

sudo nano /etc/ssh/sshd_config

To make sure SSH server on WSL works well, change Port 22 into Port 2018 or whatever you prefer.

Port 2018
ListenAddress 0.0.0.0
PermitRootLogin prohibit-password

the above is the scanty lines you have to deal with in the sshd_config. Then start the SSH service.

sudo service ssh start

Use MobaXterm to SSH

MobaXterm has not only SSH support but also full X-Server support if you need. Two editions (Home Edition and Professional Edition) are provided with free one and paid one.

I download MobaXterm Home Edition (Portable edition) which already fulfils my demand.

Create a new session and edit its configuration. Remote host is set as127.0.0.1. Remember that Port should be 2018 or the same port you decided several minutes ago. You can tweak other settings catered for your appetite.

If your Debian is running well with SSH enabled, it must work. Select Remember the Password to save the time you type in your password whenever booting the WSL.

Now enjoy WSL with the excellent terminal experience supplied by MobaXterm.

Auto-boot WSL with SSH started

It is so unpleasant to manually start SSH service each time you turn WSL on and the bot to boot WSL at the same time as you log in Windows can be the thing what you want.

Also, you will soon notice that the SSH connection goes bad when you shut down the CMD window which is quite bothering.

Here comes the solution to the three so-called problems.

Auto-start SSH service

Write a shell script named init.sh placed in /home.

sudo -S service ssh start << EOF
<your_password>
EOF

Replace <your_password> to your root password.

The object of the tiny script is to start SSH service in sudo mode when you execute this shell.

Write a VBS script on your Windows host.

Set ws = CreateObject("Wscript.Shell")
ws.run "bash /home/init.sh",vbhide

To mention that, WSL can be start up by typing bash in CMD or Powershell. The script is so self-explain that it will obviously run the init.sh as well after booting WSL.

vbhide at the end of the line tells that it runs silently in the background.

Actually, it doesn't matter that what sort of name you give to the shell above and where you place it. Just to be sure the path-to-the-shell has to be identical in two scripts.

Auto-boot WSL in background

It is much easier to achieve this goal since the big steps have got settled in the previous move.

Set the VBS script into the scheduled tasks performing when Windows host logins.

Reboot Windows and keep an eye on the Task Manager. if two processes namedinit (depends on the name of the shell) and sshd exist, then you can immediately start MobaXterm to SSH into WSL without any other keyboard job.

Job done

Now, the complete WSL with SSH workflow has been set up.

Thanks for reading :)

Build SSH for Development on Windows Subsystem for Linux的更多相关文章

  1. Bash on Ubuntu on Windows ( Windows Subsystem for Linux)

    1 #  Bash on ubuntu on Windows http://www.cnblogs.com/anonymous-ufo/p/6143480.html 1 1 如何启用Bash on u ...

  2. Windows Subsystem for Linux 环境变量

    WSL(Windows Subsystem for Linux )的环境变量是包含Linux子系统和Windows系统的,测试如下: wy@WY-PC:/mnt/c/Windows/System32$ ...

  3. Running ASP.NET Core applications on Windows Subsystem for Linux

    Setting up Linux on Windows 10 First thing is to enable Windows Subsystem for Linux. It doesn’t inst ...

  4. Windows SubSystem for Linux

    Summary of Windows SubSystem for Linux Install Ubuntu Run PowerShell as administrator and input: Ena ...

  5. Windows Subsystem for Linux(WSL)安装记录

    什么是WSL Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层.它是由微软与Canoni ...

  6. VSCode - 使用 WSL(Windows Subsystem for Linux)

    一开始我是只将 VSCode 集成的终端改成 WSL 的 Bash,结果发现内置的 GIt 用的还是 Windows 的 Git,Git Hooks 用的 Windows 的环境,上网搜了一下发现有很 ...

  7. WSL (Windows Subsystem for Linux) 的 VSLAM (Visual Simultaneous Localization and Mapping) 道路

    WSL 的 VSLAM 道路 以 Windows Subsystem for Linux 闯入 Visual Simultaneous Localization and Mapping 世界的艰难道路 ...

  8. 适用于windows10 Linux子系统的安装管理配置 How To Management Windows Subsystem for Linux WSL

    什么是WSL Windows Subsystem for Linux 简称WLS,适用于Linux的Windows子系统,可以直接在Windows上运行Linux环境(包括大部分命令行工具) Linu ...

  9. Windows10上开启WSL2(Windows Subsystem for Linux 2)及Docker Desktop For Windows

    什么是WSL2 WSL2(Windows Subsystem for Linux 2)是适用于Linux的Windows子系统体系结构的一个新版本,它支持适用于Linux的Windows子系统在Win ...

随机推荐

  1. git学习5 ecipse集成git(转载)

    原文地址:http://blog.csdn.net/hhhccckkk/article/details/10458159 有的eclipse已经自带了GIt了,就不用安装了 1: 进行安装Git,和安 ...

  2. 在IIS下配置自定义的报错页面

    这里介绍在IIS中配置自定义出错页面的方法,主要以404为例,其他状态可类推 1.远程桌面连接IIS所在的服务器,进入控制面板>系统和安全>管理工具,双击打开IIS管理器,选择需要配置的网 ...

  3. iphone配置实用工具iPhone Configuration Utility

    下载地址 http://support.apple.com/kb/DL1466 安装完毕后,在设备->控制台,可以很方便看到报错信息

  4. SpringMVC + AJAX 实现多文件异步上传

    转自:https://www.jianshu.com/p/f3987f0f471f 今天,我就这个问题来写一篇如何用 SpringMVC + AJAX 实现的多文件异步上传功能.基本的代码还是沿用上篇 ...

  5. WebRTC的拥塞控制技术<转>

    转载地址:http://www.jianshu.com/p/9061b6d0a901 1. 概述 对于共享网络资源的各类应用来说,拥塞控制技术的使用有利于提高带宽利用率,同时也使得终端用户在使用网络时 ...

  6. 201671010127 2016—2017—2 Java学习周结

    时间真是个最公平东西,只要能够好好地利用它,它可以为我们带来我们我们所想要的东西.学习Java已经有一周了,对于Java基础知识的认识也更进一步,对Java的兴趣也愈来愈浓.实现一个Java程序,主要 ...

  7. php验证是否建立数据库,否,则自动建立

    <?php /* 默认建立的数据库为test,数据表为admin,管理员只需要修改DB_PWD(即本地的服务器密码)即可,用户密码采用md5加密 */ define(DB_HOST," ...

  8. vue 跨域访问http

    axios用法: npm install axios --save-dev 2.导入: import axios from 'axios'; 3.使用($(form)需要先按装jQuery) axio ...

  9. 开发同事 Linux 实用基本操作

    Linux 有复杂的体系,有很多的命令,开发同事日常开发时,不像运维同事需要熟练使用很多命令. 下面记录下我在工作中,常用的基本命令: 一 日志查看 对于开发同事来说,日常工作中,Linux 中最常用 ...

  10. iOS 隐藏App图标

    1.在进入Info.plist文件 2.在Info.plist文件中新添加一项,把Key值设置为SBAppTags,在Type选项中选取Array 3.在Array中新添加一项Item0,Type类型 ...