##生成公钥、私钥
ssh-keygen
等同于ssh-keygen -t rsa
运行上面命令后,系统会出现一系列提示,一路回车就可。
运行结束以后,默认在/root/.ssh目录生成两个文件:
id_rsa:私钥
id_rsa.pub:公钥
导入远程主机
$ ssh-copy-id remote_ip
Now try logging into the machine, with "ssh '192.168.0.10'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
相当于执行
$ scp/root/.ssh/id_rsa.pub root@remote ip:/root/.ssh/authorized_keys
就是把公钥文件放到你想登陆的主机上
验证
$ ssh remote ip
输入 ip a 查看是否是想要登录的主机