• Requires Token2Shell version 15.1.0 or higher
  • Windows 10 April 2018 Update (1803) and
    Ubuntu 18.04 were used while preparing this post

STEP 1 Install OpenSSH server

We'll be using Ubuntu 18.04 and OpenSSH server for this example. If you're using a different Linux distribution, please consult its manual for installing an SSH server. You don't have to use an OpenSSH server; if you prefer a different sever, just make sure it's properly supported in WSL.

For more information about installing an OpenSSH server on Ubuntu 18.04, please visit:
http://token2shell.com/howto/using-wsl-from-token2shell-or-any-terminal-emulator-via-openssh-server

We'll create an Address Book entry in Token2Shell for automatically logging into WSL. In order to create such an entry, your SSH server at least supports 'password' or 'publickey' user authentication.

STEP 2 Create an Address Book entry

▮ 'password' User Authentication Method

  1. Change the user authentication preference and make sure the 'password' is the first one.
  2. Adjust the SSH port number if your SSH server is not using the default SSH port (22).
  3. Enable Auto Login and enter your WSL password. The "prompt" texts are not used for SSH connections.

▮ 'publickey' User Authentication Method

Please note that you don't have to select the "Enable X11 Forwarding" option in order to use X Window apps on WSL. Even though you're connecting to WSL via SSH, you're still in the same local computer as WSL; you can directly connect to the X server. In order to use X Window apps, just make sure your DISPLAY environment variable is correctly pointing to the X server. For example, if you're using X410, your DISPLAY environment variable should be set to 127.0.0.1:0.0.

export DISPLAY=127.0.0.1:0.0



Click "Connect" and make sure you can connect to WSL without entering any password.

STEP 3 Test starting an SSH session from Command Prompt

Open Command Prompt and try connecting to WSL and see if you can login without any password. You should use the following format for starting a session:

start t2ab:///<your-address-book-entry-path>



"<your-address-book-entry-path>" is the path to the Address Book entry created in Step 2. Please note that the extra leading slash (/) character. The path must also be URL encoded if it contains space or any HTML reserved character.

When the path to the Address Book entry created in Step 2 is "wsl-shell", your command line should be:

start t2ab:///wsl-shell








STEP 4 Create a folder for WSL related scripts and assets

It can be any folder on any drive, but for the sake of simplicity, let's create it on C: drive and name it 'wsl': c:\wsl. If you've decided to use a different folder path, please make adjustments accordingly to the scripts and registry settings described in the next steps.

We're using a VBScript and a Windows batch file (open-token2shell-here.bat) to launch Token2Shell. You can directly launch Token2Shell without those files. However, we're using them in order to simplify managing the commands (instead of editing the Windows registry, you can just edit the files) and to hide the Command Prompt window that pops up whenever Windows commands are executed.

STEP 5 Create a VBScript file for executing a batch file without any flashing Console window

We can directly execute the batch file that will be created in Step 5 for actually launching Token2Shell. However, Windows always shows a Command Prompt window when executing a batch file; we couldn't find a way to completely hide it. By using this VBScript, we can silently run the batch file and open Token2Shell.

C:\wsl\bat-launcher.vbs
If WScript.Arguments.Count <= 0 Then
    WScript.Quit
End If	

bat = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) & WScript.Arguments(0) & ".bat"
arg = ""

If WScript.Arguments.Count > 1 Then
    arg = WScript.Arguments(1)
End If

CreateObject("WScript.Shell").Run """" & bat & """ """ & arg & """", 0, False




Please note that the above VBScript automatically attaches the ".bat" file extension to its first argument and executes it as if it's a batch file in the same folder.

STEP 6 Create a Windows batch file (*.bat) for launching Token2Shell

C:\wsl\open-token2shell-here.bat
ubuntu1804.exe run "echo '<your-wsl-password>' | sudo -S service ssh start"

REM ### Need to adjust the path (%1) so it can be correctly passed as a part of the full URL
setlocal EnableDelayedExpansion
REM ### Remove the surrounding quotes ("") from %1
SET _gotopath=%~1
REM ### Replace space characters with %20's
SET _gotopath=!_gotopath: =%%20!
REM ### Replace '#' characters with %23's
SET _gotopath=!_gotopath:#=%%23!

cmd.exe /C start t2ab:///<your-address-book-entry-path>?exec=cd%%20%%22$(wslpath%%20'%_gotopath%')%%22;clear;$SHELL%%20--login




Please change the "<your-wsl-password>" to your password for WSL. "<your-address-book-entry-path>" is the path to the Address Book entry created in Step 2. Please note that the extra leading slash (/) character. The path must also be URL encoded if it contains space or any HTML reserved character as mentioned in Step 3. However, after the URL encoding, its '%' character must be again escaped as '%%' since it's used in a Windows batch file. For example, all space characters must be changed to "%%20"; a space character is first changed to '%20' (URL encoding) and its '%' character is again changed to '%%' (Windows batch file escaping).

When your password for WSL is '123456' and the path to the Address Book entry created in Step 2 is "wsl-shell", your batch file should be:

ubuntu1804.exe run "echo '123456' | sudo -S service ssh start"

REM ### Need to adjust the path (%1) so it can be correctly passed as a part of the full URL
setlocal EnableDelayedExpansion
REM ### Remove the surrounding quotes ("") from %1
SET _gotopath=%~1
REM ### Replace space characters with %20's
SET _gotopath=!_gotopath: =%%20!
REM ### Replace '#' characters with %23's
SET _gotopath=!_gotopath:#=%%23!

cmd.exe /C start t2ab:///wsl-shell?exec=cd%%20%%22$(wslpath%%20'%_gotopath%')%%22;clear;$SHELL%%20--login



WSL currently doesn't support automatically launching server programs (or daemons). Hence our OpenSSH server must be started manually but the current version of WSL now does allow having servers running in background even when all Linux terminal windows are closed. All in all, instead of immediately starting the OpenSSH server when you login to Windows, our batch file launches the server just before it's actually needed for Token2Shell.

In order to start an OpenSSH server, you need to use the 'sudo' command in Ubuntu. In our batch file, we're using the 'echo' command with 'sudo -S' in order to feed your password to the 'sudo' command. If you're using the same password as Windows login, we highly recommend changing it. WSL manages its own separate accounts from Windows, so you should set a different password (perhaps a simpler one) only for WSL.

There are other ways to start the server. But as far as we know they all focus on permanently removing the password for the 'sudo' command and require editing a system configuration file on Linux (ex. editing the '/etc/sudoers' file with 'visudo' command). Our approach of using the 'sudo -S' is much simpler and should provide more flexibility since it can also be used for other servers without changing any system file on Linux.

STEP 7 Create a registry file for setting up the right-click menu

C:\wsl\set-open-token2shell-here-menu.reg
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Directory]

[HKEY_CURRENT_USER\Software\Classes\Directory\Background]

[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell]

[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Token2Shell]
@="Open Token2Shell here"

[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Token2Shell\command]
@="wscript.exe \"C:\\wsl\\bat-launcher.vbs\" \"open-token2shell-here\" \"%V\""

[HKEY_CURRENT_USER\Software\Classes\Directory\shell]

[HKEY_CURRENT_USER\Software\Classes\Directory\shell\Token2Shell]
@="Open Token2Shell here"

[HKEY_CURRENT_USER\Software\Classes\Directory\shell\Token2Shell\command]
@="wscript.exe \"C:\\wsl\\bat-launcher.vbs\" \"open-token2shell-here\" \"%V\""






If you're not using "c:\wsl" for the scripts created in Step 5 and 6, please make sure to adjust the paths for 'open-token2shell-here.vbs' and 'open-token2shell-here.bat' according to your setup.

Once you have the 'set-open-token2shell-here-menu.reg' file, you can import it to Windows registry by double-clicking it or using the 'Import' menu from the Windows 'regedit' program.

DONE!