天天看點

SSH免密從機器A登入到機器B

ssh免密登入需要借助公鑰與私鑰。linux通過ssh-keygen生成公鑰/私鑰對。

登陸的機器有私鑰,被登陸的機器要有登入機器的公鑰,這個公鑰/私鑰對一般在私鑰主控端産生(登陸機器)

需求:機器A(10.21.144.111),通過ssh免密碼登入機器B(10.21.144.110)?

1、在機器A中生成 公鑰/私鑰對

[[email protected]]#ssh-keygen

三個回車,該指令将在/root/.ssh目錄下面産生一對密鑰id_rsa和id_rsa.pub

[[email protected] home]# cd /root/.ssh/

[[email protected] .ssh]# ll

總用量 12

-rw-------  1 root root 1679 6月  11 15:31 id_rsa

-rw-r--r--  1 root root  395 6月  11 15:31 id_rsa.pub

-rw-r--r--. 1 root root  175 2月  18 09:45 known_hosts

2、把機器A下的/root/.ssh/id_rsa.pub公鑰複制到機器B中的 /root/.ssh/authorized_keys檔案裡,先要在B機上建立好 /root/.ssh 這個目錄,用scp複制。

[[email protected] .ssh]#scp /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys    

3、機器A上修改/root/.ssh/authorized_keys的權限600

chmod 600 /root/.ssh/authorized_keys

4、機器A登入機器B

[[email protected] .ssh]# ssh 10.21.144.110

Last login: Tue Jun 11 16:43:55 2019 from testzq.com

[[email protected] ~]#

繼續閱讀