VSCode Remote Python Debugging without ssh keys

 In my October 17, 2019 post, I described remote debugging with VSCode. At this point, Python remote debugging was only possible with VSCode Insider. VSCode Insider is a version that allows you to test the latest or experimental features before applying them to VSCode. However, as time has passed, remote debugging is officially supported in VSCode.

 prerequisite

 

Install VSCode Extensions

Remote Development extension

 Install the Remote Development extension in VSCode as in the October 17, 2019 article.

 

 <install Remote Development extension>

In the October 17, 2019 article, the Remote Development extension was labeled Preview, but no longer has a preview label.

Next, search for and install the Python extension. Maybe your VSCode already has the Python extension installed.

 


Setup Remote SSH connection

On the October 17, 2019 blog, the only way to access a remote server using ssh is to use an ssh key. However, this method has several drawbacks.

 If the remote server information is changed, a new ssh key must be created. I mainly work on the Raspberry Pi and NVidia Jetson series. These single board computers use SD cards as storage space. Therefore, the SD card image is frequently replaced. When the SD card is replaced, the previously created ssh keys are no longer valid. Therefore, id/password authentication is often convenient.

Since VSCode is now able to access ssh in the id/password method, this disadvantage is eliminated.

 Now, the config file for ssh connection in VSCode was created as follows.

 

 Old Method (ssh key exchange)

Run VSCode and press Ctrl + Shift + P to search for the extension command. Then select Remote-SSH: Connect to Host ... Then select C: \ Users \ Users.ssh \ config. And add the following line: Modify the IP, User, and Private Key routes as appropriate. Refer to https://tipspiggy.blogspot.com/2019/10/remote-python-debugging-with-vscode.html for key generation method.

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host Gabia
    HostName 117.52.89.100
    User world
    IdentityFile ~/.ssh/jumpbox

 

New Method (id/password)

Run VSCode and press Ctrl + Shift + P to search for the extension command. Then select Remote-SSH: Connect to Host ... Then select C: \ Users \ Users.ssh \ config. And add the following line: Modify the IP, User. You no longer need to put an IdentityFile entry.

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host Gabia
    HostName 117.52.89.100
    User world

 

Now let's try new method.

press Ctrl + Shift + P to search for the "Remote-SSH:Connect to host ..." command. Then select your host that you just configured.

 

Then you will probably be prompted for the world user's password. If you enter the correct password, you can connect to the remote host.

 

 <Remote Server(Gabia) connected successfully>

 If you press the Explorer button and then the Open Folder button, you can specify the working directory.

 

Remote Debugging

 Remote debugging requires that you install an extension that enables remote debugging on the remote computer . Press the Extensions button or Ctrl + Shift + P and search Python again. Earlier we installed the Python module. This time we see a new "Install in SSH: Gabia" button. Clicking this button installs a remote extension for Python debugging on the Remote host.
 
 
 <Python extension installation on the remote host>
 
 If you select the Python extension in the VSCode window connected to the remote host, options for the remote host appear. Click "Install in SSH: Gabia" to install the Python extension on the remote host.
 
After installation, reload the VSCode workspace. You are now ready for Python remote debugging.
 

Code completion with IntelliSense

Most users who are familiar with IDE environments such as MS Visual Studio love to use code completion features. Code auto-completion not only speeds up development, but also greatly improves productivity by dramatically reducing the amount of typographical errors. Although the Linux development environment has some of these code autocompletion features, unlike the IDE on Windows and Mac, they often have limited functionality or require a paid product. In particular, remote development environments rarely provide this functionality. Using a remote control tool such as VNC is far from the remote development environment described in this article.
 

After installing the remote Python debugging module, VSCode can now write Python code that works on the remote computer using autocomplete. It is a new and powerful feature that you will never experience using the VI editor on a SSH terminal.
 
You can now set breakpoints by hovering your mouse next to the left number in the Python source code. Create a breakpoint at the desired location. Then press the debugger button and then the start debugger button. When asked what to debug, select Python File. This will automatically run the Python file in the current window. The program automatically stops at the breakpoint you specify. At this point, you can check the variable values ​​with the mouse and monitor the variable values ​​step by step using the left window.
 



Trouble Shooting

I use a lot of single board computers such as Raspberry Pi and Jetson Nano. Since these computers use SD cards for storage, they often change SD cards. In this case, the following errors can sometimes occur.
"VScode remote connection error: The process tried to write to a nonexistent pipe"
The main cause of this phenomenon is that the same IP address is used but fingerprint mismatch occurs when the operating system is changed. In this case, 
delete the C:\Users\.ssh\known_host file 
and try again.
This phenomenon often occurs when the operating system is changed frequently while using the same IP as in my case.
 

Wrapping up

  The Python remote debugging described above can be used not only on Raspberry Pi, but also on X64 Linux servers and SBCs using various ARM CPUs. I hope this helps you improve your productivity. Since the method introduced in the previous blog was using ssh key generation, it was inconvenient to use on single board computers such as Raspberry Pi and NVidia Jetson. However, now, not only the key generation method but also the connection can be made possible by entering the remote host account in real time. And the remote debugging function can be maintained.
 
 
 

댓글

이 블로그의 인기 게시물

VSCode - Lua programming and debugging

Remote C/C++ Debugging with VSCode #1 - Installation and simple debugging

Remote Python Debugging with VSCode