Saturday 18 March 2023

Run Remote Application

Years ago I wrote about running applications remotely. In that case I was running the remote application without interacting with it, just obtaining its output. These days I've needed something a bit differente. We want some users (with 0 linux knowledge) to run a Linux command line interactive application (select option, press Y/N, etc), from windows. The ideal solution is that they just click a shortcut and a terminal (PuTTY) opens, connects to the server and starts the application. This way the user can work on the application without knowing anything about ssh connections, navigating the filesystem, etc...

Putty can be started from the command line with the server to connect to, user and password. Furthermore, we can provide it with a file with a list of commands (-m option) to run one the connection is established. If we want the remote session and the terminal to remain open once the commands are finished, we have a flag "-t" for that. All in all we have this:

putty.exe -ssh user@server -pw myPassword -t -m commands.txt

Having the commands in a separate file can be a bit problematic for some use cases, so searching how to overcome this limitation I came across KiTTY, a PuTTY fork. It supports all the PuTTY arguments and some additional ones, like "-cmd" that allows us to pass a command to run (so obviously we can run several commands joining them with "&" or ";"). So with KiTTY we have:

kitty.exe -ssh user@server -pw myPassword -t -cmd "python3.10 /apps/my_app/main.py"

Notice that while for this specific use case of opening a terminal and connection from the command line... I'm using PuTTY and KiTTY, for my normal work with Linux Servers I use since a long, long while MobaXterm. One gorgeous piece of software, that incorporates a sftp browser, splitting your screen for multiple connecions and typing the same commands in all of them, and many, many more features. Furthermore, it's developed in Toulouse!

No comments:

Post a Comment