➜ ~ ssh-keygen Generating public/private rsa key pair. Enter file inwhich to save the key (/Users/d2x3/.ssh/id_rsa): /Users/d2x3/.ssh/a_rsa # ... ➜ ~ ssh-keygen Generating public/private rsa key pair. Enter file inwhich to save the key (/Users/d2x3/.ssh/id_rsa): /Users/d2x3/.ssh/b_rsa # ...
编辑~/.ssh/config,通过IdentityFile指定不同的私钥
Host A HostName 192.168.1.2 Port 22 User root IdentityFile ~/.ssh/a_rsa Host B HostName 192.168.1.3 Port 233 User root IdentityFile ~/.ssh/b_rsa Host * ServerAliveInterval 60
复制公钥到远程主机
➜ ~ ssh-copy-id -i ~/.ssh/a_rsa A ➜ ~ ssh-copy-id -i ~/.ssh/b_rsa B