To be fair, this isn’t just a Visual Studio Code SSH Error – it can happen with any SSH connection.
Nevertheless, I came across it because I use SSH connections to remote servers using Visual Studio Code because it’s really VERY NICE to be able to work on code on a remote server using a decent IDE. Microsoft have outdone themselves on this one.
Why Use Visual Studio Code With SSH?
Well, as I said above, because it’s just very very nice. Previously editing any PHP files, or configuration files, of Bash scripts would be done in Joe. Joe has been my Linux editor of choice since I can’t remember when. It works. It’s quick. It’s text based.
Joe does a pretty reasonable job as an editor, but I’m not sure it’s really kept up with modern standards.
Visual Studio Code though, on the other hand, is modern. It runs on Windows. It also runs on Linux on an X Session if you want it to. But I’m not using it that way. I’m using Visual Studio Code on Windows because my server is located in the USA. Running an X-Window session across that kind of distance is doable. But lags horrendously. Sure I could (and do) use XRDP at times. But why bother, when VS.Code will just do the heavy lifting for you if it’s coding you’re wanting to do.
Why NOT Use Visual Studio Code With SSH?
Well, there’s one very good reason I can think of – but it’s not a technical one. It’s merely a safety issue / convention.
If you use this method you’ll be very tempted to work on live server code.
In fact – that’s the whole reason I started using it.
But you should NEVER EVER work on live code. Not really. You should use git to version control your code, and you should develop and bug fix locally and only then deploy to the live server. And generally that’s what I do. But sometimes, occasionally, I just need a quick fix in the PHP, or Bash Script and it’s just nice to be able to do it live!
But you shouldn’t do it 🙂
SSH Error – SSH_ASKPASS: POSIX_SPAWN: No Such File Or Directory
Anyway, all that aside, if you’re using Visual Studio Code to SSH into another server – or you’re using Windows OpenSSH that comes with Windows 10 (which is a crappy old version by the way) then you may encounter this error.
ssh_askpass: posix_spawn: No such file or directory Host key verification failed.
And interestingly, it’s really obscure. You may not remember what you did to cause it. And yes, you almost certainly did cause it yourself 🙂
In my case I had set the DISPLAY environment variable because I wanted to run VcXSrv and use X-Windows on another server. It was really horribly slow anyway. And then I forgot to unset the DISPLAY environment variable when I decided it was all unworkable anyway.
And then a week later, after I’d forgotten all about it, I tried to use Visual Studio Code and got that error. I hadn’t noticed problems with my SSH anywhere else because I was using WSL’s SSH client and it doesn’t have that problem. But even if you start Visual Code under WSL, it’s still a Windows process when all is said and done.
So, if you’re getting that error, check whether you’ve set a DISPLAY environment variable in your Windows environment and if you have, you may need to remove it.