Emacs: Tramp doesn’t work
I tried to open a remote file via Emacs via Tramp.
I get a message from Emacs
Tramp: Waiting for prompts from remote shell
Emacs hung and did not respond to any action after that
Emacs was installed on Windows; the remote file was on a Linux machine.
6 Answers 6
If the account you’re connecting to uses some weird fancy shell prompt, then there is a good chance that this is what makes tramp trip.
Log in as root, then enter
(that’s a normal, standard shell (ZSH, BASH, younameit) prompt, one that tramp will understand) then switch to the user account, and launch emacs -q (to make sure that your .emacs is not causing this mess) and try to C-x C-f /sudo:root@localhost:/etc/hosts and see what’s what.
You can (not recommended) also customize the regexp that defines what tramp expects :
- Make sure the variable tramp-terminal-type is set to «dumb»
M-x customize-variable RET tramp-terminal-type
- Test that in your .*shrc and serve the correct prompt :
/.bashrc file returns immediately (by default in Gentoo). The «return» command should be removed. – avp Nov 19 ’14 at 10:50
Your Windows ssh client is the key here, and the ‘ssh’ Tramp method is almost certainly wrong.
If you’re using Cygwin, then you need to use the ‘sshx’ method, and you probably need to use ssh-agent to handle authentication. Details are here: Using tramp with EmacsW32 and cygwin, possible?
I imagine the same applies to any stand-alone ssh client which does not require a full Cygwin installation, but does use the Cygwin DLLs. (I mention this, because I’m pretty sure I remember seeing such a thing.)
If you’re using PuTTY then you want the ‘plink’ method, as Alex Ott pointed out. If the Wiki doesn’t suffice, a search here will probably turn up solutions for configuring that approach.
Other alternatives I can suggest are:
Use the Cygwin-native Emacs. That will be slower than NTEmacs, but Tramp seems to work well with the ‘ssh’ method, and password-prompting works as well.
Host a Linux VM on your Windows box, and run Emacs on that. That’s a fairly large hoop to jump through, but it’s my preferred way of using Tramp when working in Windows.
What is the best way to open remote files with emacs and ssh
I connect to the remote machine with ssh user@192.168.1.5 . When I need to open a file in the remote machine I do, e.g.,
and that opens the index.html file in the shell. I noticed that some emacs commands work but others do not work. For instance, C-w does not work; M- does not work. How can I fix this, and what is the best way to work with emacs and ssh?
I found this question but it made me more confused.
6 Answers 6
I generally prefer opening remote files from a local Emacs instance.
While running Emacs on your local machine, opening a remote file over ssh is not much different than opening any other file besides a slightly different syntax.
For ssh, you can type C-x C-f . Now, in the minubuffer you want to type /ssh:user@host:/path/to/file (Note that tab completion will work once you start typing a path. Also note the leading / character). See the full docs here.
In your example, that would be:
Now you can edit remote files over ssh in Emacs while using your local configuration and any installed packages, etc.
Just to add to the answer above, you can write shortcuts for machines that you use frequently:
This will open a dired buffer on a remote machine. You can navigate this buffer as you would a local one.
If you have set up ssh keys for the remote machine, you don’t even have to enter the password.
If you have a bunch of remote machines, you can give some recognizable name to each function, e.g. connect-cupcake , connect-kitkat and use smex package for completion.
And to add to @abo-abo’s post about «shortcuts» —
Use Emacs bookmarks. Just create bookmarks normally, when you visit a remote file or directory. Then just use C-x r b to jump to a remote bookmark, whose name you provide (with completion).
If you use Bookmark+ then remote bookmarks are highlighted specially in the *Bookmark List* , so you can recognize them more easily. And remote bookmarks that must be accessed by su or sudo ( root ) are highlighted differently.
If you use Dired+ then you can also quickly bookmark multiple remote files or directories, by visiting their containing remote directory in Dired, marking them, and hitting C-x b . No need to give the bookmarks names; they are named after the files. Even if you never use those bookmarks for navigating to the remote files, you can use them with Bookmark+ tags to organize the files and thus operate on subsets of them.
If you use Icicles then whenever you use a command to jump to a bookmark, you can narrow the completion candidates to those that are remote by hitting C-M-@ during completion.
How can I use Emacs Tramp to double hop ssh?
My campus only lets ssh access through a gateway server. So to access the cluster I am coding on I have to ssh to the gateway and then ssh to the machine I am working on. The connection is very slow at times and is frustrating to work on.
I would love to use something like tramp which I understand would have the buffer open on my local machine and only talk through the network when I save to disk. I am not very familiar with tramp at all and struggling to get it to work, especially through the double hop. The documentation says this is accomplished through defining proxies in tramp, but I am unable to understand the syntax.
Does anyone know how to use emacs to code through a double hop or have an alternate workaround for editing code through two ssh hops?
4 Answers 4
If you have Emacs 24.3 or later, see Joe’s answer for an alternative to the configuration described below. If you’ll be using this double hop more than once, it may be worth either modifying tramp-default-proxies-alist as described below, or setting tramp-save-ad-hoc-proxies to t .
If you have Emacs 23.1 or later, then the multi method is no longer supported. You can achieve the same result by configuring «proxies».
In your .emacs config file add the following:
Where HOSTB is the destination host behind HOSTA.
Then type /ssh:USERB@HOSTB: and emacs will prompt for the HOSTA password then the HOSTB password.
Tramp mode in emacs using ssh config
I think this is very basic question in using tramp, but it doesn’t work for me. I have my
/.ssh/config file that points to my amazon ec2 machine
I can easily do ssh amazon from my terminal and I go to amazon ec2 (so my config is right), but in emacs I do:
I always get this error In Aquamacs:
I also have other ssh configurations that they ssh to my virtual boxes on my local machine and they have the same problem.
I really appreciate any help.
3 Answers 3
One thing that’s worth trying is using the sshx connection method. That makes tramp try to avoid any non-standard shell configuration on the remote host.
The tramp method ssh1 forces ssh to be run in ssh v1 protocol mode with the parameter -1 . ssh v1 has known weaknesses and is insecure. Hence a lot of sites disable the ssh v1 protocol.
You can verify this from the shell with ssh -1 me@xxxx.amazonaws.com .
Try other tramp connection methods like ssh , sftp or scpx . You can see all pre-configured connection methods with C-h v tramp-methods .
If Moritz Bunkus’s answer doesn’t solve the issue, then you can configure the verbosity of tramp’s output with
M-x customize-variable RET tramp-verbose RET
In particular, level 6 is «sent and received strings» which might help you to determine whether the «Waiting for prompts from remote shell» is because it isn’t receiving a prompt pattern that it recognises, or because of some more critical failure.
If it’s simply receiving a prompt it doesn’t recognise, then you might look at customizing the tramp-login-prompt-regexp or tramp-shell-prompt-pattern variables.
(Of course if your ssh agent is working correctly, then login prompts shouldn’t be relevant.)
If you’re running Emacs in Windows, then also see these Q&As:
Using emacs tramp vs. rsync for remote development
I have been doing some remote development using emacs tramp and found that it was quite slow. Every time I save a file, it takes about 10 seconds to complete the save. So, now I am using rsync to transfer the files remotely and it works much faster, it takes about a second plus the local saves from emacs are instant. Are there any configuration options within tramp to get it to run as fast as rsync does on the command line? Are there any advantages to using tramp instead of rsync even though I am seeing such poor performance?
7 Answers 7
While tramp can be configured to use a large number of transport method, I suppose you’re using ssh to connect to the remote server.
I believe most of the time it takes to complete the operation comes from setting up a connection and authenticating. If you’re using a new enough version of OpenSSH, this can be helped by using the connection sharing feature, see ControlMaster in ssh_config(5).
I suggest you try
and see if that improves the situation.
If you’re using tramp for ssh/scp functionality, you’ll find opening a persistent SSH connection will make tramp operations a lot faster: they’ll reuse the existing connection rather than creating a fresh one each time, cutting out a great deal of cryptographic overhead without affecting security. See this article on the SSH ControlMaster functionality.
A couple of answers have mentioned enabling ControlMaster to keep a persistent ssh connection open (which avoids the expensive connection set-up / hand-shaking otherwise needed for each Tramp operation over ssh), but you don’t need to configure anything outside of Emacs to use this — if you look at the tramp-methods variable you will see there are existing methods which enable ControlMaster.
Specifically, the rsyncc and scpc methods.
Both sides of the connection need to support ControlMaster, of course (for instance Cygwin cannot do so, which is a shame for Windows users*), but I would suggest setting one of those as your tramp-default-method .
Not having a persistent connection makes extended Tramp usage pretty painful, but with one it’s incredibly usable (to the point where, given a reasonably fast connection, you can almost forget that it’s happening).
In answer to the final part of your question, yes, there are very good reasons to use Tramp instead of rsyncing the files manually. The primary one is that shell commands can be executed directly on the remote server, and you don’t even have to think about it, as Emacs takes care of the details.
For instance, from a remote-file buffer, M-x shell RET opens a shell on the remote server, and commands like M-x rgrep RET and M-x find-grep-dired RET will run the find + grep on the remote server. I believe that this applies in general to functions which invoke shell commands.
For me, that’s more than enough reason to use Tramp (unless installing Emacs on the remote server and using your local display was an option in which case, for long-term usage, I would consider doing that instead).