天天看點

Centos7.5 配置免密鑰登入

操作步驟:

1.1 生成密鑰:

[root@linux-node1 ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

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:lZUIBlcj3kfEX8VTQoNXlVuP2BTA5cvNeF/okv9NT5w root@linux-node1

The key's randomart image is:

+---[RSA 2048]----+

| ..=oo==*+X|

| + o.==.o=+|

| . + ..o=|

| . ...+B.|

| S = =|

| o o+|

| o .E=|

| o oo|

| ..+|

+----[SHA256]-----+

[root@linux-node1 ~]#

[root@linux-node1 ~]# cd /root/.ssh/

[root@linux-node1 .ssh]# ll

總用量 8

-rw-------. 1 root root 1675 6月 27 17:20 id_rsa

-rw-r--r--. 1 root root 398 6月 27 17:20 id_rsa.pub

########################################################

2.1 分發密鑰:

#ssh-copy-id ip 或 主機名

[root@linux-node1 .ssh]# ssh-copy-id [email protected]

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host '192.168.10.20 (192.168.10.20)' can't be established.

ECDSA key fingerprint is SHA256:3FvLpgF2SZ8tnDaLxx/6MOExLHQexXawRH0dAu/wgIk.

ECDSA key fingerprint is MD5:f2:3d:11:88:87:92:47:05:e2:93:ac:0a:a9:44:61:d9.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '[email protected]'"

and check to make sure that only the key(s) you wanted were added.

#################################################################

驗證:

[root@linux-node1 ~]# ssh 192.168.10.20

Last failed login: Wed Jun 27 05:50:17 EDT 2018 from 192.168.10.10 on ssh:notty

There was 1 failed login attempt since the last successful login.

Last login: Wed Jun 27 04:19:23 2018 from 192.168.10.1

[root@linux-node2 ~]# ifocn

-bash: ifocn: 未找到指令

[root@linux-node2 ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.10.20 netmask 255.255.255.0 broadcast 192.168.10.255

inet6 fe80::e690:3c3c:62ba:c9e2 prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:b5:43:96 txqueuelen 1000 (Ethernet)

RX packets 530373 bytes 297203349 (283.4 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 730583 bytes 56873359 (54.2 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

##################################################################

繼續閱讀