主頁 > 知識(shí)庫 > linux中ssh免密通信的實(shí)現(xiàn)

linux中ssh免密通信的實(shí)現(xiàn)

熱門標(biāo)簽:網(wǎng)站建設(shè) 硅谷的囚徒呼叫中心 檢查注冊(cè)表項(xiàng) 使用U盤裝系統(tǒng) 智能手機(jī) 阿里云 美圖手機(jī) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式

什么是ssh

管理員可以通過遠(yuǎn)程登陸的方式,對(duì)通過網(wǎng)相連的分散于各處的多臺(tái)主機(jī)進(jìn)行管理操作。

管理員可以對(duì)遠(yuǎn)程主機(jī)進(jìn)行如下操作:

  •  遠(yuǎn)程登陸
  • 遠(yuǎn)程命令執(zhí)行
  • 遠(yuǎn)程文件傳輸

遺憾的事情是:這些操作不安全!

使用純文本口令,并用明文發(fā)送

  • 信息可能會(huì)被截取,口令可能會(huì)被檢索
  • 未經(jīng)授權(quán)的人員使用截取的口令登陸系統(tǒng)而對(duì)系統(tǒng)造成危害

在日常操作練習(xí)時(shí),用ssh登錄其他主機(jī)時(shí),可能會(huì)每次都需要輸入登錄密碼,哪怕用scp復(fù)制東西也需要。

為了更方便快捷的切換主機(jī),ssh免密通信不失為更好的選擇;

用ssh-keygen生成密鑰,默認(rèn)保存在本地的/root/.ssh/id_rsa

然后在用ssh-copy-id分發(fā)至目標(biāo)主機(jī)之上;登錄用戶@主機(jī)名或IP地址

注意:

    1.最好是用主機(jī)名,在/etc/hosts文件中寫入主機(jī)名和對(duì)應(yīng)的IP地址;

    2.免密通信需要雙方相互認(rèn)證,所以也需要在目標(biāo)主機(jī)對(duì)本機(jī)做一次相同的操作;

[root@www ~]# ssh-keygen -t rsa -P '' 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?
[root@www ~]#ssh-copy-id -i .ssh/id_rsa.pub root@172.16.75.1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
The authenticity of host '172.16.75.1 (172.16.75.1)' can't be established.
ECDSA key fingerprint is SHA256:YXhbTS9MfK2IQC4gtOW4RL8voHvFqC1cAAMJXuF3Wec.
ECDSA key fingerprint is MD5:2c:c0:94:e8:3a:e4:74:88:c0:d8:e0:01:20:81:1d:8e.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.75.1's password: 
Number of key(s) added: 1
Now try logging into the machine, with:  "ssh 'root@172.16.75.1'"
and check to make sure that only the key(s) you wanted were added.

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:黃山 賀州 湖北 湘潭 懷化 煙臺(tái) 通遼 山南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《linux中ssh免密通信的實(shí)現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266