使用IP地址为ssh完成zsh选项卡

时间:2014-06-26 18:40:32

标签: zsh oh-my-zsh

我ssh到几台只是IP地址的机器,但我注意到一段时间后,当尝试SSH连接时,选项卡完成停止工作。我使用zsh,我可以使用ssh标签填写一个普通的域名,但是我使用的所有IP机器都没有完成标签,在这里做了什么?或者这笔交易是什么?

  • OS X - 10.9.3
  • zsh - 5.0.2

2 个答案:

答案 0 :(得分:3)

你设置了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

答案 1 :(得分:1)

您的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

所述