使用带有EmacsW32和cygwin的tramp,可能吗? [英] Using tramp with EmacsW32 and cygwin, possible?

查看:205
本文介绍了使用带有EmacsW32和cygwin的tramp,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用EmacsW32和cygwin设置Tramp时遇到问题。我已经配置emacs使用cygwin作为shell使用w32shell。我也设置HOME环境变量为c:/ cygwin / home / myusername

I have some trouble setting up Tramp with EmacsW32 and cygwin. I have configured emacs to use cygwin as shell using w32shell. I also set the HOME enviromental variable to c:/cygwin/home/myusername

问题是流浪汉似乎挂起,没有连接:

Problem is that tramp seems to hang and that no connection is made:

Tramp正在等待提示新的shell。

"Tramp waiting for prompts for the new shell".

我试图打开调试,但仍然只看到此消息。期待得到一些提示。谢谢。

I have tried to turn on debugging, but still only see this message. Looking forward to get some tips on this. Thank you.

推荐答案

注意emacs wiki上的cygwin相关信息:
http://www.emacswiki.org/emacs/TrampMode

Take note of the cygwin-related information on the emacs wiki: http://www.emacswiki.org/emacs/TrampMode

我不使用EmacsW32,但我确实成功地使用TRAMP通过ssh与Cygwin和NT Emacs。

I don't use EmacsW32, but I do successfully use TRAMP over ssh with Cygwin and NT Emacs.

我从来没有TRAMP工作没有ssh代理(即提示输入凭据) - 你注意到,它只是挂起 - 但它适用于一个,所以我没有花时间解决这个问题。假设您也乐于使用代理(并且您已经生成了您的密钥,并根据需要添加了authorized_keys文件),适用于我的方法是:

I never got TRAMP working without an ssh agent (i.e. prompting for credentials) -- as you noticed, it just hangs -- but it works fine with one, so I didn't spend time trying to resolve that. Assuming you're also happy to use an agent (and you have already generated your keys and added authorized_keys files as necessary), the approach that works for me is:


  1. 从cygwin运行ssh-agent。

  2. 通过cygwin启动NT Emacs(以便继承ssh-agent环境变量)。

  3. 使用'sshx'作为TRAMP方法(您可以在每个文件路径中手动指定它,但我建议将其默认为(setq tramp-default-methodsshx))。

这些点都在Wiki上覆盖,但你也可以自动化一些东西:

Those points are all covered at the Wiki, but you can also automate things somewhat:

对于步骤1,我的bash配置文件自动启动一个ssh代理(如果没有运行),或者如果我的身份已经过期,则提示我输入密码。 (参见下面的代码。)

For step 1, my bash profile automatically starts an ssh agent if one isn't already running, or prompts me for my passphrase if my identity has expired. (See code below.)

对于步骤2,启动emac的Windows快捷方式的目标如下:

For step 2, the target of my Windows shortcut for launching emacs looks like this:

C:\cygwin\bin\bash.exe --login -cenv HOME = \`cygpath'%APPDATA%'`\/ cygdrive / c / emacs / emacs-23.1 / bin / runemacs.exe

- login 参数意味着我的bash配置文件被执行,这确保了第一步一直在emacs启动之前处理。

The --login argument means my bash profile is executed, which ensures that step 1 has always been taken care of before emacs is started.

(设置 / code>对于TRAMP不是必需的,但是%APPDATA%是NT Emacs下的默认值,这可以防止Cygwin主目录优先,您的emacs配置一致,无论是否使用此快捷方式运行它。)

(Setting HOME isn't necessary for TRAMP, but %APPDATA% is the default under NT Emacs, and this prevents the Cygwin home directory from taking precedence, therefore keeping your emacs config consistent regardless of whether you use this shortcut to run it.)

最后,这里是我的cygwin .bash_profile的代码,它管理我的ssh代理。

Finally, here's the code from my cygwin .bash_profile that manages my ssh-agent. It's a bit hacky, but it works for me.

请注意,我在4小时(14400秒)后过期我的身份。 TRAMP可以挂起后发生(如前所述,我从来没有它提示我的凭据),所以请注意这个问题。键入 C-g 可阻止其尝试连接。要恢复连接,你通常可以启动另一个cygwin shell,重新输入您的密码,然后TRAMP将再次很高兴。偶尔,它仍然没有响应,但杀死* tramp *缓冲区将排除。不要过期的身份应该避开这个问题,当然是可以接受的。

Do note that I expire my identity after 4 hours (14400 seconds). TRAMP can hang after that happens (as mentioned before, I never got it to prompt me for credentials), so be aware of this issue. Type C-g to stop it from trying to connect. To resume connectivity, you can generally just start up another cygwin shell, re-enter your passphrase, and then TRAMP will be happy again. Occasionally it has remained unresponsive, but killing the *tramp* buffer will sort that out. Not expiring your identity should circumvent this issue, of course, should that be acceptable.

SSH_ENV="${HOME}/.ssh/environment"

# Run ssh-agent, if one is not already running
function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent -t 14400 | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" >/dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" >/dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ >/dev/null || {
        start_agent;
    }
    #if our ssh-added identity has expired (see -t option to ssh-agent)
    #then we need to re-add it
    if ! /usr/bin/ssh-add -l >/dev/null; then
        /usr/bin/ssh-add;
    fi
else
    #no ssh-agent running at the moment
    start_agent;
fi

这篇关于使用带有EmacsW32和cygwin的tramp,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆