在进行ssh免密登录时,如果存在多个服务端需要单独配置密匙,那么我们就可以使用config来简单管理
步骤:配置密匙》推送服务器》创建config文件》测试登录
配置密匙
与之前教程一样唯一区别在于使用ssh-keygen -t rsa后出现
Enter file in which to save the key (*/.ssh/id_rsa):时,输入密匙的名称再回车
例:Enter file in which to save the key (*/.ssh/id_rsa):localhost
推送服务器
推送时,需要使用-i来指定密匙
ssh-copy-id -i ~/.ssh/localhost sshtest@localhost
其它操作与之前教程一样。
配置config文件
先执行命令:cd ~/.ssh/,然后vi ./config
格式:
Host 昵称
HostName 域名、ip
IdentityFile 指定密匙
示例:
Host localhost
HostName 127.0.0.1
IdentityFile ~/.ssh/localhost
多服务器示例:
Host localhost
HostName 127.0.0.1
IdentityFile ~/.ssh/localhost
Host localhost1
HostName 192.168.0.1
IdentityFile ~/.ssh/localhost1
[更多查看:利用 ssh 的用户配置文件 config 管理 ssh 会话]
当你发现你配置了多密钥以后,始终无法进行ssh的时候。 别忘了
ssh-add -K [path/to/your/ssh-key]