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

歡迎訪問 生活随笔!

生活随笔

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

linux

Linux笔记-设置SSH公钥免密码登录

發布時間:2025/3/15 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux笔记-设置SSH公钥免密码登录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

三臺內網機對應IP和名稱如下:

名稱ip
Centos 7 MySQL Master192.168.79.134
Centos 7 MySQL Slave192.168.79.136
Centos 7 MySQLManager192.168.79.137

?

在上面三臺機器上個添加/etc/hosts

192.168.79.134 mydb1 192.168.79.136 mydb2 192.168.79.137 mydb3

任意找一臺機器,生成ssh的key,然后復制到其他兩臺機器上:

[root@localhost ~]# pwd /root [root@localhost ~]# mkdir .ssh mkdir: 無法創建目錄".ssh": 文件已存在 [root@localhost ~]# cd .ssh/ [root@localhost .ssh]# ls [root@localhost .ssh]# 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: SHA256:7xiZZui/S6hW6yaYj+vo8bOYobUrg2Ie65n0Rh5EjuM root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | | | . | | + | | o o | |. o S | | E o .o + | |.=+o..o.B . | |B+#*ooo+ + | |O&BO=+o.=o. | +----[SHA256]-----+ [root@localhost .ssh]# [root@localhost .ssh]# [root@localhost .ssh]# [root@localhost .ssh]# [root@localhost .ssh]# cat id_rsa.pub >> authorized_keys

隨后賦予權限:

[root@localhost .ssh]# chmod 700 ~/.ssh [root@localhost .ssh]# chmod 600 ~/.ssh/authorized_keys [root@localhost .ssh]# cd ..

將.ssh文件復制到其他2臺主機上個:

[root@localhost ~]# scp -r .ssh 192.168.79.136:/root/ The authenticity of host '192.168.79.136 (192.168.79.136)' can't be established. ECDSA key fingerprint is SHA256:ctYIvL3p2kOgf/2h8VbDCrHTJUqKcDNvNsLV/s+bJYQ. ECDSA key fingerprint is MD5:76:cf:8a:bb:be:4c:b8:37:73:7c:05:48:11:de:33:2b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.79.136' (ECDSA) to the list of known hosts. root@192.168.79.136's password: id_rsa 100% 1675 1.7MB/s 00:00 id_rsa.pub 100% 408 500.0KB/s 00:00 authorized_keys 100% 408 493.7KB/s 00:00 known_hosts 100% 176 181.8KB/s 00:00 [root@localhost ~]# scp -r .ssh 192.168.79.137:/root/ The authenticity of host '192.168.79.137 (192.168.79.137)' can't be established. ECDSA key fingerprint is SHA256:ctYIvL3p2kOgf/2h8VbDCrHTJUqKcDNvNsLV/s+bJYQ. ECDSA key fingerprint is MD5:76:cf:8a:bb:be:4c:b8:37:73:7c:05:48:11:de:33:2b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.79.137' (ECDSA) to the list of known hosts. root@192.168.79.137's password: id_rsa 100% 1675 1.5MB/s 00:00 id_rsa.pub 100% 408 499.5KB/s 00:00 authorized_keys 100% 408 412.5KB/s 00:00 known_hosts 100% 352 399.2KB/s 00:00 [root@localhost ~]#

測試通過ssh mydb1等測試下要不要密碼:

[root@localhost ~]# ssh mydb1 The authenticity of host 'mydb1 (192.168.79.134)' can't be established. ECDSA key fingerprint is SHA256:ctYIvL3p2kOgf/2h8VbDCrHTJUqKcDNvNsLV/s+bJYQ. ECDSA key fingerprint is MD5:76:cf:8a:bb:be:4c:b8:37:73:7c:05:48:11:de:33:2b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'mydb1,192.168.79.134' (ECDSA) to the list of known hosts. Last login: Sat Jun 6 10:37:55 2020 [root@localhost ~]# ssh mydb2 Last login: Sat Jun 6 10:50:04 2020 from mydb1 [root@localhost ~]# ssh mydb3 Last login: Sat Jun 6 10:50:51 2020 from mydb2 [root@localhost ~]#

?

總結

以上是生活随笔為你收集整理的Linux笔记-设置SSH公钥免密码登录的全部內容,希望文章能夠幫你解決所遇到的問題。

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