John Siu Blog

Tech - Business Tool, Personal Toys

Alpine Linux and VS Code Remote SSH

☰ Table of Content

How to do it in 2022.

Back Story

Have been trying to do this on and off for years. VS Code always complains “The remote host may not meet VS Code Server’s prerequisites for glibc and libstdc++” when doing remote ssh to an Alpine box. Then the connection will fail.

A few month ago I finally seat down and went through VS Code logs on both ends. The first thing I notice was Alpine box didn’t install wget nor curl by default, and VS Code server need at least one of them. Installing wget solved half the problem and I got more logs.

Then I hit on the actual glibc/libstdc++ issue. libstdc++ was solved by a simple apk add. And after some googling, it turned out Alpine had a gcompat package that provides glibc function on top of musl. Installing it and VS Code remote ssh start working.

It Works

So it turned out to make VS Code remote ssh to Alpine box is as simple as running following on the Alpine box:

1
apk add gcompat libstdc++ curl bash git

You can replace curl with wget. And aside from that, VS Code is also looking for bash.

I had the above discovery post in vscode-remote-release back in Mar. But the story didn’t end there.

Dropbear/OpenSSH

dropbear is an OpenSSH alternative for ssh server and client. It is simpler and smaller. If you don’t need ssh tunnel, sftp/scp to and from the Alpine box, you can just stick with it.

However I was having issues with ssh tunneling, sftp/scp, etc. On the Alpine box, I end up switching out dropbear and back to openssh server and client.

1
2
apk del dropbear
apk add openssh

Unlike Ubuntu, following need to be set manually for sshd on Alpine.

/etc/ssh/sshd-config

1
2
AllowTcpForwarding yes
PermitTunnel       yes

VS Code and Alpine Git

Though Alpine Linux git install in /usr/bin/git, same location as most other Linux and Mac OS, VS Code cannot load the default environment and has to be set manually.

Connect VS Code to the Alpine box, then in settings, open the remote tab(Remote [SSH: <hostname>]):

alpine-vscode-git

Click upper right icon to open json file, and put following:

1
2
3
{
	"git.path": "/usr/bin/git",
}

Git will start working after reconnect.

BusyBox

busybox is another brilliant package that replaces lot of common linux commands with a single binary.

However, if you are doing lot of shell scripting and rely on some “standard” command line options and/or output, you are likely to run into issue.

I installed following in my Alpine box:

1
apk add zsh grep curl wget git jq git util-linux-misc procps

Conclusion

Turn out the steps required are not difficult and hope VS Code will one day support ssh-ing to Alpine out of the box.

John Siu

Update: 2022-05-24
comments powered by Disqus