在Linux环境下,两台主机之间传输文件一般使用scp命令,通常用scp命令通过ssh获取对方linux主机文件的时候都需要输入密码确认。不过通过建立信任关系,可以实现不输入密码。
这里假设主机A用来获到主机B的文件。
1. 在主机A上执行如下命令来生成配对密钥:
ssh-keygen -t rsa
按照提示操作,注意,不要输入passphrase。提示信息如下
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b root@localhost.domain
2. 将 .ssh 目录中的 id_rsa.pub 文件复制到 主机B 的 ~/.ssh/ 目录中,并改名为 authorized_keys ,假设B主机的IP为。
scp .ssh/id_rsa.pub 192.168.2.12:/root/.ssh/authorized_keys
以后从A主机scp到B主机就不需要密码了。
这里假设主机A用来获到主机B的文件。
1. 在主机A上执行如下命令来生成配对密钥:
ssh-keygen -t rsa
按照提示操作,注意,不要输入passphrase。提示信息如下
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
ff:8e:85:68:85:94:7c:2c:46:b1:e5:2d:41:5c:e8:9b root@localhost.domain
2. 将 .ssh 目录中的 id_rsa.pub 文件复制到 主机B 的 ~/.ssh/ 目录中,并改名为 authorized_keys ,假设B主机的IP为。
scp .ssh/id_rsa.pub 192.168.2.12:/root/.ssh/authorized_keys
以后从A主机scp到B主机就不需要密码了。