5 Steps: Setup VS Code for Remote Development via SSH from Windows to Linux system | by Gong Na | Towards Data Science

Remote development is a very popular function in VS Code. Their official documentations provide standard instructions to configure it in a general way. But when I connect to the remote Linux server from Windows system, I always got the below Corrupted MAC on input error and hard to find a complete solution in one place.
So, this article will provide a VS Code guidance specific for the remote connection between Windows and Linux systems via key-based SSH which also handles the Corrupted MAC on input error.
For software developers, they usually develop new features locally then test on remote servers.
For data scientists, they need the extra computing resources such as the remote GPU node to support the large data processing.
For DevOps engineers, one of their main tasks is to deploy different products on different servers and this requires frequent remote configurations.
Installed VS Code.
You can download from their website and do the essential setups by following my previous guidance. This guidance also works for the general development workspace.
Installed OpenSSH on both local Windows and remote Linux systems.
To be short, this will allow you work with ssh . You can check it on both systems via ssh -V . It will return you the version of the installed OpenSSH on your system. Otherwise, the OpenSSH is not installed. And you can install it from here for Windows and here for Linux.
Now, let’s start ~ 🚀
Overview of ContentsStep 1: Install the Remote-SSH Extension in VS CodeStep 2: Verify the SSH Connection in PowerShellStep 3: Enable the Remote Connection in VS CodeStep 4: Generate SSH Key PairsStep 5: Copy the Public Key to the Remote Server
[following setup is based on Win10 PowerShell]
Launch VS Code -> click Extension icon in the left bar -> search Remote-SSH in search box -> install it:
Then you will see a little remote connection icon shown in the bottom-left of the Status Bar:
Click the top left Terminal or the shortcut ctrl+shift+` to open a PowerShell terminal in VS Code -> if it’s not PowerShell, change it from here:
Verify SSH connection by executing ssh username@hostname in PowerShell. (It doesn’t matter if you run this in a conda env or not)
If you can successfully login to the remote server, you are ready for the next step.
💢 If you get the Corrupted MAC on input error as below:
✅You can try the following solution:
Run ssh -Q mac first. It will return a list of all available MAC cryptographic algorithms on your local system:
Then, choose one of them as you like and connect to the remote server again by adding the selected algorithm with -m option:
ssh -m hmac-md5-96 username@hostname
You many need to try several times until you find the algorithm which is supported by your remote Linux server.
Now, you should be able login to the remote server and ready for the next step.
Click the left-bottom remote connection icon -> select Remote-SSH: Open Configuration File...
or you can directly open the ssh configuration file from your local home directory ~/.ssh/config .
Add your remote server information in configuration file in below format:
Host [hostname]  HostName [hostname]  User [username]  MACs [optional; if you have the MAC error in Step 2, add the available algorithm which you found to here]
In case you have multiple servers to connect, just keep the format and append them one by one.
At the end, you will get a config file like below: (We will come back to the IdentityFile in the next step)
Now, you should be able to connect to the remote server without MAC error.
Click the remote connection icon in the bottom-left -> select Remote-SSH: Connect to Host... -> you will see a list of remote servers maintained in your config file -> click your target server (you may need to enter your login password)
After the successful connection, you will be navigated to a new VS Code window and the remote host name is shown in the bottom-left:
Until here, you have successfully setup a workable remote development workspace via VS Code. But, not finish yet.
If you stop here, you will be asked to enter the login password every time when you issue a remote connection. And you also need to enter the password for the each single operation on that remote server via VS Code even just open a folder. This would be really annoying. On the other hand, password logins is not secure enough. It’s easy to use and understand for everyone, but this convenience somehow sacrifices the security level. Password can be easily broken by the brute-force attack.
Therefore, instead of entering password in VS Code, it’s better to use SSH public and private key pairs to do the authentication.
In VS Code Powershell terminal, execute the command:
ssh-keygen
During the key generation, it will prompt:
This allows you define a location to store the keys. Press ENTER to leave it as default.
This allows you enter and double confirm a password to protect your private key (when you type, it won’t display your password). After this, you need to enter this password when you use the private key in future. This is an extra protection. You can press ENTER to skip it.
After the creation, you will see a key’s random art image. And your key pairs are stored in the default hidden ~/.sshdirectories:
To double check, you can review he key pairs in above location via:
cd ~/.sshls
You will see two new files id_rsa which stores the private key and id_rsa.pub which stores the public key. Run cat [filename]to check the key content.
If everything is fine. Now, you can add the path of the private key ~/.ssh/id_rsain the ssh configuration file as Step 2 with name of IdentityFile:
Just keep in mind, one public key can be used multiple times and ❗ do NOT share your private key to anyone.
Login to the remote server via VS Code or any other terminal with password. Check if you have the authorized_keys file under~/.ssh directory. If not, create one by following commands:
cd ~/.ssh  touch authorized_keys 
authorized_keys is the default file name defined by OpenSSH used to store the public keys. You can maintain multiple public keys in this file. Make sure that each key is on a single line and no line-breaks in the middle of the key.
Then maintain your public key (the content in your local ~/.ssh/id_rsa.pub file) in this remote file:
vim authorized_keys -> press i to shift to INSERT mode -> paste your public key content here -> press ESC + : + wq to write into and quit the file -> recheck it by cat authorized_keys .
Now, your secure and convenient remote development workspace in VS Code is ready!
Just go back to your VS Code. Issue a new remote connection. Now, you should be able to connect to the remote server without the password and work on it just as you are locally. Have fun!