How to Remote Develop or Debug over SSH Connection?

While developing code for a different machine, either a huge server or a tiny embedded host, you’ll need to develop on a remote environment. Your connection of choice probably will be SSH, and here is how to develop in that setup.

You have two different choices in this setup. First, you can develop locally and deploy through your connection. Another one is to develop on the target machine directly. For the first alternative, you’ll need a decent PC with appropriate tooling and deploy your code through SFTP or some other file transfer protocol. For the second one, you can even develop from your phone, and you’ll need the connection all the time. I’ll focus on the second one for this article.

Developing with an SSH – connected host

In that setup, you can either use a terminal SSH interface + a terminal text editor like vim, or use a program to sync files over SFTP, that will allow you to type on your own machine.

1- SSH + vim

In that setup, you’ll need no tooling in your machine what-so-ever. This development can be done from your cell phone. It only demands a stable connection to the target machine. What you’ll need is:

A machine that can connect via SSH

This can be your favorite Android phone, or a cranky old notebook from 90s. No computation power will be used on this machine. If you’re using a phone here, I recommend a screen connection and a keyboard for your phone. Otherwise, developing on it will be a pain in your ass. What you’ll do is:

>ssh {user_name}@{IP_address}

to initiate connection. Following:

>vim {filename}

for editing the file you need. Just remember to use source control for this, and commit frequently.

However, I’m not fond of developing via vim on a different machine, that is hard to use for me and I’m not a fan of text editors running over SSH. So, moving to the other alternative.

2- Using a tool to code over SSH

There are lots of tools to develop over SSH. My choice here is to use Visual Studio Code. In order to use it you’ll need vscode remote-SSH extension to work. In local, you need an OpenSSH compatible SSH client, and a running SSH server on the remote machine.

After installing all requirements, you’ll need to issue the command Remote-SSH: Connect to Host… from the command palette(F1). Then you’ll enter the username and IP address of the remote machine. Then if the user has a password, you’ll get a window to enter it.

After connection fulfilled, you’ll end up using a newly opened window that is working on the target machine! You can install new extensions, open up files, folders or workspaces on it. Good luck!

For more information on vscode SSH development, see

Debugging over a connection? How to use gdb to debug over TCP?

Debugging your code over TCP connection is totally possible, and it’s even easier than coding over a connection. For this, you will need to start a gdb server on remote host, and connect to it via gdb.

gdbserver Setup

gdbserver is a program that makes it possible to remotely debug other programs. Running on the same system as the program to be debugged, it allows the GNU Debugger to connect from another system. So how to set up this connection. You just need issue:

>gdbserver :{Some port} {Some program}

After, gdbserver starts to listen for a gdb connection to be done on the target machine.

How to connect to the gdbserver socket

To debug a program remotely after starting the gdbserver on the target, you need to use gdb on your local machine. If you’re going to debug a different architecture, either set architecture from your machine by:

(gdb) set architecture {some architecture}

Or use a toolkit which is provided to you by the manufacturer, possibly a linaro gdb.

If your gdb does not include your target architecture, you may install the packet gdb-multiarch for Debian-based OS es. If you’re using a RHEL-based distro like CentOS, you will not find any on your yum repos. Advice is to use the toolkit if this is the case.

So, this is the case of the remote developing/debugging. Hope this is helpful to y’all. More articles can be found on my homepage. See you around!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *