centos7 ssh免密登入配置--ssh公钥命令行添加

前提,至少两台服务器。
如:
host1: 10.1.2.1
host2: 10.1.2.2

已centos7为例:

1、在host1重新生成ssh相关key文件,输入一下命令,一路回车。
[root@mmyr ~]# 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:fK7Ej96N4UzY216O70X/ipytWyfBRkjGnbH+yoUuvIs [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|           .o..o |
|           o..o. |
|            . o  |
|       .     +   |
|        S .   = .|
|       . =   . =.|
|        + =.  = *|
|       . O Oo@ *.|
|       .+ E.&OX..|
+----[SHA256]-----+

2、上传公钥到host2服务器。
>ssh-copy-id -i /root/.ssh/id_rsa.pub -p 22 [email protected]

3、验证登入
> ssh [email protected]

4、在host2上重复步骤1、2,完成免密登入。

你可能感兴趣的:(centos7 ssh免密登入配置--ssh公钥命令行添加)