假设需要为两台主机建立ssh key以便抓取、更新代码,主机A:111.111.111.111,主机B:222.222.222.222。
首先,用两个账户([email protected]与[email protected])生成两个ssh,分别存到不同位置,例如:
# 主机A的存在/c/user/.ssh/id_rsa ssh-keygen -t rsa –C “[email protected]” # 主机B的存在/c/user/.ssh/hostb/id_rsa ssh-keygen –t rsa –C “[email protected]” /c/user/.ssh/hostb/id_rsa # 当要求输入存储位置时,输入
然后,在/c/user/.ssh/目录下,建立名为“config”的文件,输入以下内容:
Host 111.111.111.111 HostName 111.111.111.111 PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Host 222.222.222.222 HostName 222.222.222.222 PreferredAuthentications publickey IdentityFile ~/.ssh/hostb/id_rsa
最后,测试一下:
$ ssh -T 111.111.111.111 $ ssh -T 222.222.222.222
时间: 2024-11-08 00:16:15