Emacs Tramp ssh 双跳

发布于 2024-11-04 05:15:47 字数 1201 浏览 1 评论 0原文

有人可以帮我设置 Emacs Tramp 来进行双跳吗? 我想在 machine2.abc.def.edu 上工作,我只能通过 machine1.abc.def.edu 连接到它。我的用户名是 myname,两台机器上的用户名相同。

我尝试添加 .emacs:

(add-to-list 'tramp-default-proxies-alist
          '("\\`machine2\\.abc\\.def\\.edu\\'"
            "\\`myname\\'"
            "/ssh:machine1\\.abc\\.def\\.edu:"))

这是我对手册内容的最佳猜测解释。然后我这样做: Cx Cf /ssh:machine2.abc.def.edu 或者: Cx Cf /ssh:[email protected]

但两者都给出:

ssh: Could not resolve hostname ssh: nodename nor servname provided, or not known
Process *tramp/scpc ssh* exited abnormally with code 255

和我的 Aquamacs无法退出,必须从 shell 中杀死...这里有一个 2 年的线程有同样的问题。我已经尝试了那里的答案:

(add-to-list 'tramp-default-proxies-alist
          '("machine2.abc.def.edu"
            nil
            "/ssh:[email protected]:"))

具有相同的结果...也适用于我能想到的所有组合...不过,在 machine1.abc.def.edu 上进行远程编辑效果很好。

Could somebody please help me setup Emacs Tramp to do a double hop?
I want to work on machine2.abc.def.edu to which I can connect only through machine1.abc.def.edu. My username is myname, on both machines same.

I've tried to add .emacs:

(add-to-list 'tramp-default-proxies-alist
          '("\\`machine2\\.abc\\.def\\.edu\\'"
            "\\`myname\\'"
            "/ssh:machine1\\.abc\\.def\\.edu:"))

This is my best guess interpretation of what's in the manual. Then I do:
C-x C-f /ssh:machine2.abc.def.edu
or:
C-x C-f /ssh:[email protected]

But both give:

ssh: Could not resolve hostname ssh: nodename nor servname provided, or not known
Process *tramp/scpc ssh* exited abnormally with code 255

And my Aquamacs can't be quitted and have to killed from shell... There is a 2 years thread here with same question. I've tried the answer from there:

(add-to-list 'tramp-default-proxies-alist
          '("machine2.abc.def.edu"
            nil
            "/ssh:[email protected]:"))

With same results... also for all combinations I could come up with... Remote editing on machine1.abc.def.edu works fine, though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜光 2024-11-11 05:15:49

好吧,让我们尝试一些不同的东西,而不是打开隧道。您的 .emacs 文件中的以下内容怎么样:

(add-to-list 'tramp-default-proxies-alist 
             '("\\`machine2\\'" 
               nil 
               "/ssh:%[email protected]:"))

这与您在论坛帖子中找到的代码有两点不同:

  1. 它在目标主机周围添加了刻度
    名称(要避免的 Emacs 正则表达式语法
    匹配部分名称)
  2. 它仅使用
    目标中的子域名
    主持人(您在评论中报告
    下面你不能 ssh 到
    machine2 当您使用完整的
    域名)

当您尝试访问 machine2 上的文件时这有帮助吗?

Okay, let's try something different then, without opening a tunnel. How about the following in your .emacs file:

(add-to-list 'tramp-default-proxies-alist 
             '("\\`machine2\\'" 
               nil 
               "/ssh:%[email protected]:"))

This is different from the code you found in the forum post in two points:

  1. it adds ticks around the target host
    name (Emacs regexp syntax to avoid
    matching partial names)
  2. it uses only
    the subdomain name in the target
    host (you reported in a comment
    below that you cannot ssh to
    machine2 when you use the full
    domain name)

Does that help when you try to access a file on machine2?

不回头走下去 2024-11-11 05:15:49

设置从 machine1 到 machine2 的 ssh 隧道(假设 sshd 在 machine2 上的端口 22 上运行):

machine1.abc.def.edu> ssh -f -N -L 2222:localhost:22 machine2.abc.def.edu

然后从 Emacs 连接到 machine2,如下所示:

/ssh:machine1.abc.def.edu#2222

或将以下行添加到您的 .emacs:

(add-to-list 'tramp-default-proxies-alist
             '("\\`machine2\\.abc\\.def\\.edu\\'" nil
               "/tunnel:machine1.abc.def.edu#2222:"))

Set up an ssh tunnel from machine1 to machine2 (assuming that sshd runs on port 22 on machine2):

machine1.abc.def.edu> ssh -f -N -L 2222:localhost:22 machine2.abc.def.edu

Then either connect to machine2 from Emacs like this:

/ssh:machine1.abc.def.edu#2222

or add the following line to your .emacs:

(add-to-list 'tramp-default-proxies-alist
             '("\\`machine2\\.abc\\.def\\.edu\\'" nil
               "/tunnel:machine1.abc.def.edu#2222:"))
沧笙踏歌 2024-11-11 05:15:48

答案是使用 ssh_config 中提供的 ssh_proxy 命令。记录在此处此处。基本上,您在 ssh 文件夹中创建一个配置文件,您可以在其中写入快捷方式。快捷方式之一是通过另一个端点使用代理。所有快捷方式都适用于任何使用 ssh 的工具,包括 git 和 emacs。

Host endpoint2
     User myusername
     HostName mysite.com
     Port 3000
     ProxyCommand ssh endpoint1 nc -w300 %h %p

Host endpoint1
     User somename
     HostName otherdomainorip.com
     Port 6893

在此示例中,运行ssh端点2将自动跳转到端点1。

The answer it to use the ssh_proxy command available in ssh_config. Documented here and here. Basically you create a config file in your ssh folder that you can write shortcuts in. One of your shortcuts is to use a proxy through another end point. All of your shortcuts work for any tool that uses ssh including git and emacs.

Host endpoint2
     User myusername
     HostName mysite.com
     Port 3000
     ProxyCommand ssh endpoint1 nc -w300 %h %p

Host endpoint1
     User somename
     HostName otherdomainorip.com
     Port 6893

In this example running ssh endpoint2 will automatically hop through endpoint1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文