Autossh for Synology Diskstation
by kacang bawang
This article is about compiling autossh
for Synology Diskstation devices. The resulting pre-built binary for aarch64
will also be provided for download at the end of the post.
Autossh
is a binary wrapper for regular ssh
that takes care of things related to keeping track of whether the connection is still intact, and restart it if it isn’t so. You need it to run long-lasting ssh tunnels, which will invariably crap out and need to be restarted sooner or later. In the case of the Diskstation, perhaps the most obvious use-case is to maintain a tunnel to a reverse proxy somewhere on a VPS, such that your Diskstation can be accessible from the wider internet, via a proper domain with a proper certificate.
After a quick search of the available packages, I did not see autossh
among them. That means we have to build it. The most helpful resource in this regard is SynoCommunity. They have created an entire build environment that includes the tools to publish the resulting “app” in the “app store”. Here we will deal with only the first part of the process, that is, the cross-compilation. The reader is invited to continue from where I left off, and get this thing published. Unless I beat you to it, haha.
The environment. The process is described pretty well here, so I will just say that I followed it and installed docker from the ppa’s via apt-get. Installation was smooth (Mint 18.04). Don’t forget to
1 |
make setup |
The compilation. The build system expects a makefile in the /spksrc/cross/[your_package_name]
directory. Just follow suit from other makefiles in the /cross/
directory. Here is what I ended up with.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PKG_NAME = autossh PKG_VERS = 1.4g PKG_EXT = tgz PKG_DIST_NAME = $(PKG_NAME)-$(PKG_VERS).$(PKG_EXT) PKG_DIST_SITE = https://www.harding.motd.ca/autossh EXTRACT_PATH = $(WORK_DIR) DIST_TARGET_DIR = $(DIST_NAME)-$(PKG_VERS) PKG_DIR = $(PKG_NAME)-$(PKG_VERS) DEPENDS = #none HOMEPAGE = https://www.harding.motd.ca/autossh/ COMMENT = Automatically restart SSH sessions and tunnels LICENSE = Freeware GNU_CONFIGURE = 1 CONFIGURE_ARGS = ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes --without-manpages include ../../mk/spksrc.cross-cc.mk |
The other quirk is the configure script for autossh
check the location of the ssh binary. There is probably a flag to force this, but I did not find it immediately (let me know if you figure it out and I will update the makefile). Instead, I just did
1 |
touch /bin/ssh |
before compilation. That path is where the ssh
binary is on my Diskstation.
1 |
make arch-aarch64 |
With that, it should compile and produce a binary like this: autossh.zip. Now, you should upload it to your Diskstation and run it. See if it outputs the welcome message. If yes, then great success, you can start using it. You may want to make it run at system start. At the time of this writing Diskstation uses upstart, so that’s the kind of script we will need to write. See autossh upstart script here.
UPDATE
Here is my init script
1 2 3 4 5 6 7 8 9 |
start on syno.network.ready #06 = reboot stop on runlevel [06] respawn respawn limit 5 60 #reverse proxy exec /path/to/autossh -M 0 -N -p 22 -i /var/services/homes/username/.ssh/id_rsa -R 1111:localhost:80 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "StrictHostKeyChecking=no" -o "BatchMode=yes" remoteuser@remotehost.com |
you can also work with tmux. I work with tmux from synocommunity and then with the script ssh -p 22 -N -R 9008: localhost: 9008 -o “ServerAliveInterval 60” -o “ServerAliveCountMax 3” -o “StrictHostKeyChecking = no” -o “BatchMode = yes” root@1.2.3.4 Tmux always runs in the background and you can always run it again with the command in the terminal tmux a. Sorry my english is not good.
Thanks for sharing Damien!