5

I'm able to use TRAMP fine for reading/writing files on a remote server. I only have to login to the server the first time I open a file, and from then on I can open files without being prompted to login again.

However, when I run commands through TRAMP, I have to login every time. For example, if I run M-x grep ENTER grep -nH -r foo ENTER, I need to login every time I run that grep command. I've tried increasing the TRAMP log level and even debugging through the TRAMP code, but I haven't been able to figure out why it can't reuse the same SSH connection to run commands.

This is on OS X. Running M-x version shows GNU Emacs 24.5.1 (x86_64-apple-darwin14.5.0, NS apple-appkit-1348.17) of 2015-08-24. Note that I cannot simply make the login process easier by using keys or caching my password, because the server I'm connecting to uses 2fac auth.

1 Answer 1

7

Emacs knows two basic commands for running external processes, call-process for synchronous processes, and start-process for asynchronous processes. For the remote case, these commands have been extended as process-file and start-file-process.

Remote synchronous processes use always the same ssh connection Tramp uses for its internal commands. Asynchronous processes will not block Tramp doing its job, a new ssh connection is used therefore.

If you consult the grep docstring, you'll read that it is called asynchronously.

However, the second remote connection reuses the credentials of the first connection if possible. For this, ssh is called like ssh -q -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none hostname. Doesn't this work for you?

4
  • To make this work always you can put somthing like Host myhost ControlMaster auto ControlPersist 4h ControlPath /tmp/ssh_%h_%p_%r Where myhost could be * if you want all host to keep a master connection. Commented Jun 30, 2016 at 13:05
  • 1
    In this case, you must unset Tramp's own setting. Setting tramp-use-ssh-controlmaster-options to nil shall be sufficient. Commented Jun 30, 2016 at 13:50
  • Thanks for the explanation Michael, that clears up what's happening. Even though the TRAMP logs show an SSH command that looks like the one you posted, I still need to supply two factor auth to the server on each connection. This may be an unavoidable consequence of using two factor auth, or it may just be some configuration that needs to be tweaked, I'm not sure (or it could be a bug?).
    – gsgx
    Commented Jun 30, 2016 at 15:03
  • For further analysis, I would need details. But this isn't something we shall discuss here. You could ask on the Tramp mailing list. Commented Jun 30, 2016 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.