日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux远程登录ssh免密码配置方法

發布時間:2025/4/16 linux 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux远程登录ssh免密码配置方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇文章主要介紹了linux遠程登錄ssh免密碼配置方法,需要的朋友可以參考下
一、情景

公司剛上幾臺Linux,現在要把主機之間都能遠程ssh免密碼登陸。

二、原理
很簡單,使用ssh-keygen 在主機A上生成private和public密鑰,將生成的public密鑰拷貝到遠程機器主機B上后,就可以使用ssh命令無需密碼登錄到另外一臺機器主機B上。

三、步驟

主機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?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命令會將指定的公鑰文件復制到遠程計算機

[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: <主機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登陸主機B驗證是否需要密碼

[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、登陸成功后,我們需要在主機B也做下以上3步,這樣就可以相互免密碼ssh登陸。(如果有多臺主機,每臺主機都做下相同操作,以方便以后管理)。寶寶起名寶典

5、權限問題
建議用其他用戶做ssh登陸的話,調整目錄文件權限
設置authorized_keys權限

chmod 644 authorized_keys

設置.ssh目錄權限

chmod 700 -R .ssh

6、要保證.ssh和authorized_keys都只有用戶自己有寫權限。否則驗證無效。

總結

以上是生活随笔為你收集整理的linux远程登录ssh免密码配置方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。