VSCode as Terminal for SSH, WSL, and Docker Container

I found MS-VSCode IDE when I learned typescript about 7 years ago. My favorite was and still is vi(mproved) because it always works on any system including windows. However, I also needed an IDE in order to code efficiently. I should be able to debug my code in the language that I write in. Additionally, I tried Cloud9 IDE that is a web app running on nodejs. Along the way, the Cloud9 IDE became burdensome and VSCode won my heart. It’s free (as in free beer), light, fast yet features-rich. Furthermore, it’s very popular. Something that is rare coming from Microsoft.

It’s riding its popularity with growing numbers of its extensions. I believe you can get any editor extension that you can think of. From handling any document format, live share, cloud client for aws, azure, google-cloud, alibaba cloud, and so on and so forth.

After all, such functionalities I use the most is the terminal for SSH, WSL, and Docker Container.

Let’s click the green corner on the lower left of VSCode window: terminal

Then there is a drop-down to connect to: drop-down

Terminal for SSH

The bash shell comes for free on any Unix-like OSes and MacOS X. However, on MS-Windows you better install it from MSYS2 or git-scm.

Select ‘Open SSH Configuration File…” from the drop-down list. It’s usually $HOME/.ssh/config file.

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host lgs-docker-swarm
    HostName 13.52.49.102
    User ubuntu
    IdentityFile ~/.ssh/devcluster.pem

Host rpi-zero
    HostName rpi-zero.fake.com
    User ryan
    Password password1

You can manage the ssh connections in this ssh configuration file. The Password property is optional and if it’s omitted then the password will be asked later.

You can also select the remote host from the toolbar on the left most column “Remote Explorer”: remote-explorer-SSH-Targets

Once you’re connected to the remote host, you can use vscode as a file explorer too: file explorer

And all the extensions work on the remote host too. Here is the docker extension on the remote ssh host: docker extension

Of course, the most important one is the remote host terminal: remote host terminal

Terminal for WSL

WSL (Windows Subsystem for Linux) is a compatibility layer for running Linux binary executables natively on MS-Windows (currentlly: Windows 10, Windows 11, and Windows Server 2019).

wsl02

The same thing is for connecting to WSL. You may install several WSL2(s) in order to work with Linux natively on windows: remote-explorer-WSL-Targets

When you’re connected to a distro, you can use vscode as a file explorer: file explorer

Therefore you don’t really need to run window manager on WSL. I’ll explain on how to run X11 apps on WSL in the next post.

Terminal for a Docker Container

Lastly is to attach to a docker container: attach to a docker container

You can use vscode as a file explorer and open a folder: file explorer

Then open the terminal to work on this container: terminal

VSCode is my main app on MS-Windows, Mac OS X, and any Unix-like OSes.

comments powered by Disqus