实验环境是CentOS7:
ssh-keygen产生公钥和私钥对。
ssh-copy-id:将本机的公钥使用ssh协议复制到远程的客户端,ssh协议的公钥和私钥一般存放于~/.ssh下
#主机 [root@~ localhost]#ssh-keygen -t rsa #其后也可以跟-P表示输入密码; [root@~ localhost]#ssh-keygen -t rsa -P "123456" [root@~ localhost]#ls ./.ssh id_rsa id_rsa.pub
#远程连接测试:
[root@~ localhost]#ssh root@172.16.252.182
Last login: Thu Jul 6 13:27:34 2017 from 172.16.251.1
#IP为客户端地址 [root@~ localhost]#ssh-copy-id -i .ssh/id_rsa.pub root@172.16.252.182 #在客户端查看: #传之前 [root@~ localhost]#ls ./.ssh known_hosts #传之后:authorized_key为传过来 [root@~ localhost]#ls ./.ssh authorized_keys known_hosts