How to edit remote files within Emacs when a program automatically runs after you SSH

30 Nov

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.



Posted by on November 30, 2015 in Emacs, Lisp, Programlama


Tags: , , ,

2 responses to “How to edit remote files within Emacs when a program automatically runs after you SSH

  1. Erwin

    December 1, 2015 at 15:26

    for the authentication problem, you could send a key to the virtual machine with ssh-copy-id

    • Emre Sevinç

      December 2, 2015 at 10:17

      Indeed. Though I’m trying to find a simpler way with one less step (that does not involve yet another command): That is passing the SSH parameters (I’ve written above) to Emacs / TRAMP in one go.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: