这里假设主机A用来获到主机B的文件。
在主机A上执行如下命令来生成配对密钥:
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:
45:13:ec:31:f9:3d:25:54:7b:5f:03:40:ba:e9:76:cd root@bindiry-ubuntu
按三次回车。
为 ~/.ssh 目录设置权限:
chmod -R 755 .ssh
将 .ssh 目录中的 id_rsa.pub 文件复制到 主机B 的 ~/.ssh/ 目录中,并改名为 authorized_keys ,同样给该目录设置权限。
到主机A中执行命令和主机B建立信任,例(假设主机B的IP为:192.168.0.3):
scp ~/.ssh/id_rsa.pub 192.168.0.3:/root/.ssh/authorized_keys
下面就可以用scp命令不需要密码来获取主机B的文件了
希望对你有所帮助