我使用ssh登录多台只有IP地址的机器,但我注意到之前尝试ssh时,Tab键补全不再起作用了。我使用zsh,在ssh时可以自动补全常规域名,但我使用的所有IP机器都无法自动补全了,这是怎么回事?是出了什么问题吗?
- 操作系统:OS X - 10.9.3
- 终端工具:zsh - 5.0.2
您是否设置了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
~/.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
(该链接介绍了如何使用OpenSSH和Zsh实现远程Tab补全)known_hosts
中的条目了吗? - Francisco
~/.ssh/known_hosts
文件的第一列(即第一个空格之前的部分;awk '{print $1}' ~/.ssh/known_hosts
)是什么样子的?它包含主机名和 IP 地址(或者可能是逗号分隔的列表),还是只有哈希值(可能以|1|
开头)? - Adaephonknown_hosts
的问题,您可以尝试删除所有条目,只留下一个条目,看看行为是否仍然存在。(不要忘记在此之前备份它 :-) ) - Adaephon