linux遠(yuǎn)程登錄ssh免密碼配置方法
一、情景
公司剛上幾臺(tái)Linux,現(xiàn)在要把主機(jī)之間都能遠(yuǎn)程ssh免密碼登陸。
二、原理
很簡單,使用ssh-keygen 在主機(jī)A上生成private和public密鑰,將生成的public密鑰拷貝到遠(yuǎn)程機(jī)器主機(jī)B上后,就可以使用ssh命令無需密碼登錄到另外一臺(tái)機(jī)器主機(jī)B上。
三、步驟
主機(jī)A:
1、 生成公鑰和私鑰文件id_rsa和id_rsa.pub (敲3下回車即可)
[root@bogon ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
67:da:0d:79:e0:d6:2b:cd:7d:22:af:51:7e:9c:75:fe root@bogon
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| . + |
| S B o . o|
| * * = o+|
| . o B +.=|
| . + +.|
| ... E|
+-----------------+
2、ssh-cop-id命令會(huì)將指定的公鑰文件復(fù)制到遠(yuǎn)程計(jì)算機(jī)
[root@bogon ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.1.250.166
The authenticity of host '10.1.250.166 (10.1.250.166)' can't be established.
RSA key fingerprint is c8:9d:6d:92:55:77:3d:3e:af:f5:cb:18:80:5a:47:93.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.1.250.166' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed - POSSIBLE BREAK-IN ATTEMPT!
root@10.1.250.166's password: <主機(jī)B的登陸密碼>
Now try logging into the machine, with "ssh 'root@10.1.250.166'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
3、然后ssh登陸主機(jī)B驗(yàn)證是否需要密碼
[root@localhost ~]# ssh 10.1.250.166
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed - POSSIBLE BREAK-IN ATTEMPT!
Last login: Wed Oct 21 10:05:39 2015 from 10.1.250.141
[root@bogon ~]#
4、登陸成功后,我們需要在主機(jī)B也做下以上3步,這樣就可以相互免密碼ssh登陸。(如果有多臺(tái)主機(jī),每臺(tái)主機(jī)都做下相同操作,以方便以后管理)。
5、權(quán)限問題
建議用其他用戶做ssh登陸的話,調(diào)整目錄文件權(quán)限
設(shè)置authorized_keys權(quán)限
chmod 644 authorized_keys
設(shè)置.ssh目錄權(quán)限
chmod 700 -R .ssh
6、要保證.ssh和authorized_keys都只有用戶自己有寫權(quán)限。否則驗(yàn)證無效。
本文出自 “好大的刀” 博客
- Linux配置遠(yuǎn)程SSH無密碼登錄
- 菜鳥學(xué)Linux命令:ssh命令(遠(yuǎn)程登錄)
- 通過 SSH 在遠(yuǎn)程 Linux 系統(tǒng)上運(yùn)行命令的方法
- Linux下使用SSH遠(yuǎn)程執(zhí)行命令方法收集
- Linux 遠(yuǎn)程管理及sshd服務(wù)驗(yàn)證知識(shí)點(diǎn)詳解
- ssh遠(yuǎn)程無法訪問linux的問題及解決
- Linux如何關(guān)閉遠(yuǎn)程ssh密碼登錄
- Linux實(shí)現(xiàn)搭建ssh并允許使用root遠(yuǎn)程
- Linux中SSH遠(yuǎn)程訪問和控制的實(shí)現(xiàn)
相關(guān)文章
ubuntu下讓python腳本可直接運(yùn)行的實(shí)現(xiàn)方法
今天小編就為大家分享一篇ubuntu下讓python腳本可直接運(yùn)行的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
Linux集群/分布式環(huán)境下session處理的五種策略詳解
這篇文章主要給大家介紹了關(guān)于Linux集群/分布式環(huán)境下session處理的五種策略,文中通過示例代碼及圖片介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09
Linux系統(tǒng)設(shè)置PATH環(huán)境變量(3種方法)
這篇文章主要介紹了Linux系統(tǒng)設(shè)置PATH環(huán)境變量(3種方法),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
CentOS6 配置Nginx,MySql,php-fpm開機(jī)啟動(dòng)的方法
這篇文章主要介紹了CentOS6 配置Nginx,MySql,php-fpm開機(jī)啟動(dòng)的方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
Linux 創(chuàng)建子進(jìn)程執(zhí)行任務(wù)的實(shí)現(xiàn)方法
下面小編就為大家分享一篇Linux 創(chuàng)建子進(jìn)程執(zhí)行任務(wù)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過來看看吧2018-01-01

