SSH免密登錄
服務(wù)器A實(shí)現(xiàn)免密登錄服務(wù)器B仰挣。(基于Linux服務(wù)器)
實(shí)現(xiàn)過(guò)程
一拂铡、服務(wù)器A公鑰的生成
服務(wù)器A上命令行界面輸入下面命令实柠,會(huì)在當(dāng)前用戶目錄下新建[.ssh]文件夾橱脸,文件夾內(nèi)包含id_rsa(私鑰)與id_rsa.pub(公鑰)
服務(wù)器A:~ nicholas.joey$ ssh-keygen -t rsa -C "你的郵箱"
服務(wù)器A:~ nicholas.joey$ cd .ssh
服務(wù)器A:.ssh nicholas.joey$ ls -al
total 40
drwx------ 6 nicholas.joey staff 192 2 3 14:13 .
drwxr-xr-x+ 47 nicholas.joey staff 1504 2 3 14:13 ..
-rw-r--r-- 1 nicholas.joey staff 263 2 3 14:13 config
-rw------- 1 nicholas.joey staff 2602 11 14 14:08 id_rsa
-rw-r--r-- 1 nicholas.joey staff 570 11 14 14:08 id_rsa.pub
-rw-r--r--@ 1 nicholas.joey staff 6270 2 3 09:14 known_hosts
二抒和、目標(biāo)服務(wù)器B的處理
當(dāng)前用戶目錄下是否存在[.ssh]文件夾,沒(méi)有則新建[.ssh]文件夾并賦予 700 權(quán)限汗菜。
并創(chuàng)建文件 authorized_keys让禀。將其服務(wù)器A創(chuàng)建的id_rsa.pub(公鑰)內(nèi)容復(fù)制在 authorized_keys 文件中。
[服務(wù)器B ~]$ mkdir .ssh/
mkdir: 無(wú)法創(chuàng)建目錄 “.ssh/”: 文件已存在
[服務(wù)器B ~]$ chmod 700 .ssh/
[服務(wù)器B ~]$ cd .ssh/
[服務(wù)器B .ssh]$ touch authorized_keys
[服務(wù)器B .ssh]$ vim authorized_keys
[服務(wù)器B .ssh]$ cat authorized_keys
ssh-rsa ***** 741779841@qq.com
結(jié)尾
實(shí)現(xiàn)上述兩步陨界,服務(wù)器A就可通過(guò)SSH免密登錄服務(wù)器B
服務(wù)器A:~ nicholas.joey$ ssh root@192.168.0.106
Authorized users only. All activities may be monitored and reported.
Last login: Wed Feb 3 16:12:41 2021 from
[服務(wù)器B ~]$
還可以自定義名稱進(jìn)行免密登錄巡揍,在其服務(wù)器A[.ssh]文件夾中新建 config 文件
Joey:~ nicholas.joey$ cat .ssh/config
#本地開(kāi)發(fā)環(huán)境
#自定義名稱
Host joey
#服務(wù)器B地址
HostName 192.168.0.106
#服務(wù)器B用戶名
User root
#驗(yàn)證方式為公鑰方式
IdentityFile ~/.ssh/id_rsa
Joey:~ nicholas.joey$ ssh joey
Authorized users only. All activities may be monitored and reported.
[服務(wù)器B ~]$