Emacs terminal (from multi-term) can automatically detect a folder path. So performing C-x C-f from a local directory, automatically provides the path to that directory to open any relevant files.

My questions is how to do the same for a remote directory that was accessed through ssh from emacs terminal? Since, if I perform C-x C-f, it only tries to open the local directory from which ssh connection was launched. How to automatically pass information to tramp to help open the files in the remote directory?

I'm looking for something similar to this question, but for term or multi-term, since shell does not seem to recognize the local alias and other shortcuts that are stored in ~/.bashrc of the remote server.

1 Answer 1


Tramp works on the basis of default-directory. If you run a shell in Emacs, and you perform ssh in that shell, the buffers's default-directory is still the local path the shell was started from. You have three options to adapt default-directory:

  • Start the shell while you are visiting a remote file or directory. The shell doesn't run on your local host, but on the remote one. You don't need to perform any ssh'ing in the shell, because you're already there. default-directory is set proper.

  • Use the local shell, and run your ssh command. After that, change the default directory of that buffer via M-x cd RET /ssh:user@host:.

  • Use eshell. You can change the host you are running your programs inside eshell via cd /ssh:user@host:. The most flexible solution, if you want to contact several remote hosts.

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.