centos7 ssh免密登录

1.在sshbridge执行下列命令生成 id_rsa.pub文件并将其拷贝到目标机器

[root@sshbridge .ssh]# hostname
sshbridge
[root@sshbridge .ssh]# pwd
/root/.ssh
[root@sshbridge .ssh]# ll
total 0
[root@sshbridge .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:PPMXXA6x3FQeWFuObO2HZPPx7Pr0DcuvA85nMbAVP4Y root@sshbridge
The key's randomart image is:
+---[RSA 2048]----+
|            . ++o|
|           . B.=+|
|            + @=+|
|       .   ..E.O+|
|        S   o++ B|
|         +  o.o..|
|          .o...oo|
|           .o.+=o|
|             o===|
+----[SHA256]-----+
[root@sshbridge .ssh]# ll
total 8
-rw-------. 1 root root 1675 Feb 26 01:47 id_rsa
-rw-r--r--. 1 root root  396 Feb 26 01:47 id_rsa.pub

[root@sshbridge .ssh]# scp id_rsa.pub root@centos238:/root/.ssh/authorized_keys_from_sshbridge
The authenticity of host 'centos238 (192.168.56.238)' can't be established.
ECDSA key fingerprint is SHA256:DMe1Nlx4gjT+7CSPbCR38H6f22y2SCk7bq+e3lezHJA.
ECDSA key fingerprint is MD5:a5:7c:c0:68:37:5b:69:d5:12:a6:24:ba:b5:8e:49:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'centos238,192.168.56.238' (ECDSA) to the list of known hosts.
root@centos238's password: 
id_rsa.pub                                                                                      100%  396   293.7KB/s   00:00    
[root@sshbridge .ssh]# 

2.在目标机器上:

[root@centos238 .ssh]# hostname
centos238
[root@centos238 .ssh]# pwd
/root/.ssh
[root@centos238 .ssh]# ll
total 4
-rw-r--r-- 1 root root 396 Feb 26 01:03 authorized_keys_from_sshbridge
[root@centos238 .ssh]# cat authorized_keys_from_sshbridge > authorized_keys
[root@centos238 .ssh]# ll
total 8
-rw-r--r-- 1 root root 396 Feb 26 01:04 authorized_keys
-rw-r--r-- 1 root root 396 Feb 26 01:03 authorized_keys_from_sshbridge
[root@centos238 .ssh]# 

3.在sshbridge上验证ssh免密登录

[root@sshbridge .ssh]# hostname
sshbridge
[root@sshbridge .ssh]# ssh centos238
Last login: Tue Feb 26 00:44:28 2019 from sshbridge
[root@centos238 ~]# hostname
centos238
[root@centos238 ~]# 

猜你喜欢

转载自blog.csdn.net/zyp361161/article/details/87934931