【问题标题】:zsh tab completion for ssh using IP Address使用 IP 地址的 ssh 的 zsh 选项卡完成
【发布时间】:2014-06-26 18:40:32
【问题描述】:

我 ssh 到几台只是 IP 地址的机器,但是我注意到不久前,当尝试 SSH 到它们时,选项卡完成停止工作。我使用 zsh,我可以使用 ssh 完成一个常规域名,但是我使用的所有 IP 机器都不再完成 tab,这里有什么问题吗?或者有什么关系?

  • OS X - 10.9.3
  • zsh - 5.0.2

【问题讨论】:

  • ~/.ssh/known_hosts 的第一列(直到第一个空格;awk '{print $1}' ~/.ssh/known_hosts)看起来如何?是否有主机名和 IP 地址(可能是逗号分隔的两者列表)还是只有哈希值(可能以 |1| 开头)?
  • 我有一个主机名和 IP 地址列表。根本没有哈希。唯一奇怪的是 [localhost]:2224
  • “奇数”是非标准端口的表示法(2224 而不是 22)。它不应该对这个问题负责,我也有。要排除 known_hosts 的问题,您可以尝试删除除一个条目之外的所有条目,然后查看行为是否仍然存在。 (不要忘记事先备份它:-))

标签: zsh oh-my-zsh


【解决方案1】:

你设置了use-ip样式吗?
zstyle ':completion:*' use-ip true
文档说默认情况下会从主机数据库中删除 IP 地址。 use-ip 允许完成它们。
http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-use_002dip_002c-completion-style

【讨论】:

    【解决方案2】:

    您的 ssh 可能正在对 known_hosts 上的条目进行哈希处理?

    一般来说,ssh IMO 的最佳可用性解决方案是创建 ssh 主机别名,然后在命令行中使用别名。例如。给你添加这样的东西~/.ssh/config

    Host foo
      # HostName also accepts numeric IP addresses
      HostName XXX.ZZZ.YYY.BBB
    

    那你就用scp backup.tar foo:

    查看man ssh_config 了解更多信息。来自手册:

     HashKnownHosts
             Indicates that ssh(1) should hash host names and addresses when they are added to ~/.ssh/known_hosts.  These hashed names
             may be used normally by ssh(1) and sshd(8), but they do not reveal identifying information should the file's contents be
             disclosed.  The default is “no”.  Note that existing names and addresses in known hosts files will not be converted auto‐
             matically, but may be manually hashed using ssh-keygen(1).  Use of this option may break facilities such as tab-comple‐
             tion that rely on being able to read unhashed host names from ~/.ssh/known_hosts.
    

    好的,请忽略以上内容,我在评论中看到情况并非如此,但将其留在那里以供参考。

    PS:您始终可以使用类似以下内容的方式手动设置要由 zsh 完成的主机:

    hosts=(foo.bar.com faa.bar.com fee.bar.com)
    zstyle ':completion:*:hosts' hosts $hosts
    

    或者做一个更复杂的版本,比如这里描述的https://www.maze.io/2008/08/03/remote-tabcompletion-using-openssh-and-zsh/index.html

    【讨论】:

    • 这确实通过创建 SSH 到 IP 的快捷方式解决了我的问题。但并没有解决为什么只是 IP 地址不为 ssh 填写标签,而普通域名却可以的问题。
    • 您是否检查过 SSH 现在是否正在加密 known_hosts 处的条目?
    • @Mentch 好的,我在 cmets 中看到了你 known_hosts 没有散列的问题。你在使用 oh-my-zsh 吗? (经常会引发这样的麻烦)。请注意,oh-my-zsh 对 ssh 的 ip-completion 进行了代码处理。
    • 是的,我正在使用 oh-my-zsh
    猜你喜欢
    • 2010-10-08
    • 2013-02-14
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多