Emacs: Tramp doesn't work

家住魔仙堡 提交于 2019-11-27 03:15:48

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

PS1="> "

(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 :

M-x customize-variable RET tramp-terminal-prompt-regexp

My approach :

  1. Make sure the variable tramp-terminal-type is set to "dumb"

M-x customize-variable RET tramp-terminal-type

  1. Test that in your .*shrc and serve the correct prompt :
case "$TERM" in
"dumb")
    PS1="> "
    ;;
xterm*|rxvt*|eterm*|screen*)
    PS1="my fancy multi-line \n prompt > "
    ;;
*)
    PS1="> "
    ;;
esac
phils

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:

  1. 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.

  2. 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.

Had you checked Emacs wiki for solution? ssh is in PATH? It's also recommended to use plink on MS Windows - see section "Inline methods" in Tramp documentation

Well, this is a defect of tramp.

The real solution is to prevent loading .bashrc when tramp is used. (because now it is PS1, but it can be PATH, or any other thing that your .bashrc will do that will displease tramp...).

This can be done by asking ssh to set an environment variable, and testing it in .bashrc:

Add this to ~/.emacs:

(require 'tramp-sh nil t) (setf tramp-ssh-controlmaster-options (concat "-o SendEnv TRAMP=yes " tramp-ssh-controlmaster-options))

and that at the beginning of ~/.bashrc:

if [ ! -z ${TRAMP-x} ] ; then return fi

Another default of tramp is that it doesn't have a variable to pass random arguments to the ssh command, we have to piggy-back on tramp-ssh-controlmaster-options.

Adobe

By the way -- if You need tramp to sudo -- You can actually sudo without tramp using sudoedit.

Currently I'm using this bash function:

erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!