本帖已被设为精华帖!
在进行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