Linux笔记-设置SSH公钥免密码登录
生活随笔
收集整理的這篇文章主要介紹了
Linux笔记-设置SSH公钥免密码登录
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
三臺內網機對應IP和名稱如下:
| 名稱 | ip |
| Centos 7 MySQL Master | 192.168.79.134 |
| Centos 7 MySQL Slave | 192.168.79.136 |
| Centos 7 MySQLManager | 192.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公钥免密码登录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络协议文档阅读笔记-Introduct
- 下一篇: Linux笔记-centos7编译安装s