1.ssh免密登录:准备两台Linux虚拟机,第一台可以免密登录到第二台机器,ssh禁止root用户远程登录
首先,开启两台虚拟机,192.168.18.128为第一台机器,192.168.18.129作为第二台机器。
生成一个2048B大小rsa类型的认证密钥。
[root@localhost ~]# ssh-keygen -t rsa -b 2048
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:g9MREYf3vZZNkCogVsFuuFmXtHzmtAxt14Jq/PHR0ww root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| o*=. . |
| o +oo o |
| . +.= = + o |
| .o+.B X E o|
| o=So @ o X.|
| o. .+ = =.=|
| . . + ..|
| . . |
| |
+----[SHA256]-----+
切换路径为/root/.ssh/id_rsa,查看文件是否存在。
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls -l
total 12
-rw-------. 1 root root 1831 Oct 7 19:33 id_rsa
-rw-r--r--. 1 root root 408 Oct 7 19:33 id_rsa.pub
-rw-r--r--. 1 root root 176 Sep 24 14:16 known_hosts
将一号虚拟机产生的公钥复制到二号虚拟机的/root/.ssh/目录下。
[root@localhost .ssh]# scp /root/.ssh/