1.生成秘钥
[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:t5aFaWRHf+yTwSy104Ys36JBAQ6BRoMtOoaNUqt3TDw root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| +o.o...o . |
| . o +. o . ++oo|
| = + o + +.+*=|
|+ * E o = o.=+|
|.o + . S = o ooo|
|. . o o + o ..|
| . . + . |
| . |
| |
+----[SHA256]-----+
记住这个文件夹,生成密钥对在/root/.ssh
[root@localhost ssh]# ll /root/.ssh/id_rsa
-rw------- 1 root root 1679 Nov 7 16:31 /root/.ssh/id_rsa
[root@localhost ssh]# ll /root/.ssh/
total 12
-rw------- 1 root root 1679 Nov 7 16:31 id_rsa
-rw-r--r-- 1 root root 408 Nov 7 16:31 id_rsa.pub
-rw-r--r-- 1 root root 175 Oct 24 16:29 known_hosts
进入/root/.ssh
2.上传公钥到对面的机器里 默认端口号可以不指定,特殊端口指定 -p 端口号
公钥传到对面的/root/.ssh/authorized_keys
[root@localhost ssh]# ssh-copy-id -i id_rsa.pub root@192.168.254.137
3.验证是否可以不输入密码远程登录
[root@localhost .ssh]# ssh 'root@192.168.254.132'