服務器准備工作:
1.登錄到服務器修改sshd的配置文件
vi /etc/ssh/sshd_config
找到以下內容取消注釋#
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
2.如果修改了配置文件需要重啟sshd服務
/sbin/service sshd restart
本機配置:
1.生成公鑰和私鑰
ssh-keygen -t rsa
默認在 ~/.ssh目錄生成兩個文件:
id_rsa :私鑰
id_rsa.pub :公鑰
2.導入公鑰認證文件
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3.復制公鑰到服務器
scp ~/.ssh/id_rsa.pub xxx@host:/home/id_rsa.pub
4.將公鑰導入到認真文件(在服務器進行)
cat /home/id_rsa.pub >> ~/.ssh/authorized_keys
5.服務器修改權限
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
6.修改本季mac下的配置文件 ~/.ssh/config
Host test Hostname 192.168.11.11 Port 22 User root IdentityFile ~/.ssh/id_rsa
7.終端執行 ssh test鏈接遠端服務器