If you are used to TRAMP functionality of Emacs to edit remote files without leaving the comfort of your beloved editor on your host machine, you do your best to keep it working even when different conditions arise. In my case, I’ve been recently working with virtual machines at work and the product that I’m working on is configured to run some program automatically right after I log into the machine via SSH. This prevents TRAMP functioning correctly with its default settings, because instead of receiving the shell prompt immediately, it receives from the machine the final line of the program that automatically runs and expects the user enter some response:
... some text menu options ... ... Please make a selection >>
Above that line, the text menu says that the user should enter 0 to exit the program or some other menu option to continue. Therefore, I had to find a way to tell Emacs that it had to send a 0 after it connects to the machine. The high-quality TRAMP manual was immediately helpful by providing a relevant example and I came up with the following:
After evaluating the Emacs Lisp code above I was able to browse and edit files on my virtual machine by simply trying to open the following in my Emacs (for details please see various ways to open remote files):
Emacs immediately asked me to enter the password, and then in the background interacted with the program and sent 0 to exit it, and finally showed me the list of files that I can edit starting from the / directory (Note that I have already set up my virtual machine for port redirection, this is why I can connect via SSH using localhost and port number 2222).
Now, the only thing that remains is to find out the simplest way to pass some SSH parameters to Emacs and TRAMP, such as:
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
and when I say simplest way I mean something simpler than this proposed solution. I’ll update this blog entry when I find out a solution that satisfies my simplicity criteria.