tramp.el with a small target
A Tramp connection issue in a limited Unix environment
Recently I needed to edit some files on an old-school shared web host. That host had a severely limited Unix environment, so I could access it via ssh and use basic shell commands, but most of the usual utilities were missing. No perl, no python, but sed and awk were present. Based on the presence of jk_lsh
I suppose it was a jailkit-based chroot jail.
Anyway, Emacs and tramp.el to the rescue! Or not:
Tramp: 'getconf PATH' not successful, using default value "/bin:/usr/bin". Tramp: Opening connection nil for remote using ssh...failed
According to the manual, Tramp needs to run ls
, test
, find
and cat
, all of which were available… but the connection methods have “other required programs”. Apparently getconf
is one, and there is a .tramp_history
file on the remote host (so it did manage to connect!) which indicates it was also trying to run stty
and uname
:
(cd ~/) 2>/dev/null; echo tramp_exit_status $?
set +o vi +o emacs
stty -inlcr -onlcr -echo kill '^U' erase '^H'
echo foo
echo \"`uname -sr`\" 2>/dev/null; echo tramp_exit_status $?
Neither stty
or uname
was available, and the effects of stty
might be difficult to replicate. Furthermore, the ssh connection method needs some way to encode and decode files in ASCII, such as uuencode or base64, and none of the options were present. It wouldn't be too hard to implement base64 in awk, or I guess I could download busybox… but there has to be a simpler way?
Luckily Tramp has the scp connection method, which doesn't need any encoding programs. It appears that even that needs to run getconf PATH
, getconf PIPE_BUF /
and uname -sr
. But those are easy to fake:
#!/bin/sh case "$1" in PATH) echo $PATH ;; PIPE_BUF) echo 512 ;; *) exit 1 esac
and
#!/bin/sh echo Linux 2.5
To make Tramp really use scp and not fall back to ssh for small files, we also need
(setq tramp-copy-size-limit nil)
somewhere in Emacs config. Et voilà! Now I can edit files in that tiny little chroot jail.