A為本地主機
B為遠程主機
AB都是linux
在A上:
建立認證公鑰和私鑰
ssh-keygen -t rsa
將公鑰文件上傳到服務(wù)器上的home
scp ~/.ssh/xxx.pub username@hostname:path
在B上:
在userhome下創(chuàng)建.ssh文件夾
mkdir .ssh
修改文件夾權(quán)限
chmod 700 .ssh
將客戶端傳過來的公鑰文件中的內(nèi)容加入到authorized_keys中
cat xxx.pub >> .ssh/authorized_keys
修改authorized_keys權(quán)限
chmod 644 .ssh/authorized_keys
如果在生成密鑰的時候自己指定了文件名龄恋,則需要在ssh客戶端全局配置文件/etc/ssh/ssh_config中添加如下配置
IdentityFile /path/to/your_id_rsa
也可以為每個服務(wù)器指定一個Host配置:
Host hostname
IdentityFile /path/to/your_id_rsa
如果在連接時出現(xiàn)如下錯誤:
Agen admitted failure to sign using the key
則使用ssh-add指令將私鑰加進來
ssh-add ~/.ssh/your_id_rsa