SSH password-free login configuration

SSH password-free login configuration

Generate key file locally:

$ ssh-keygen

output:

Generating public/private rsa key pair.

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

Enter passphrase (empty for no passphrase): Continue to press enter directly

Enter same passphrase again: Continue to press enter directly

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:

10:98:86:e7:78:c8:24:87:dc:3a:8a:30:ca:08:4e:8c root@min1

The key's randomart image is:

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

|.... the. |

|o.+.= . |

|o=.* . |

|E=+ o . |

|@...    S        |

|=o |

|                 |

|                 |

|                 |

+-----------------+

The above situation indicates that the key is successfully generated and placed in the root/.ssh/id_rsa file without a password.

Copy the key file to the target machine

$ ssh-copy-id 192.168.71.10

output:

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

RSA key fingerprint is fa:a9:1b:a8:d3:f8:4b:39:23:c6:4b:e6:21:c1:df:99.

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

Warning: Permanently added '192.168.71.10' (RSA) to the list of known hosts.

[email protected]'s password: 输入目标机192.168.71.10密码

Now try logging into the machine, with "ssh '192.168.71.10'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

至此表示拷贝成功了,输出说可以尝试登陆了。

登陆测试

[root@min1 ~]$ ssh 192.168.71.10

Last login: Wed Nov 22 00:58:34 2017 from 192.168.71.1

[root@min2 ~]$ ^C

这样就可以远程运行脚本及操作各种指令了。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325297010&siteId=291194637
Recommended