在两台机器的两个用户之间建立安全的信任关系后,可实现执行scp命令时不需要输入用户密码。
1. 在机器A上root用户执行 ssh-keygen 命令,生成建立安全信任关系的证书。
[root@A root]# ssh-keygen -b 1024 -t rsa
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: ……
注意:在程序提示输入 passphrase 时直接输入回车,表示无证书密码。
上述命令将生成私钥证书 id_rsa 和公钥证书 id_rsa.pub,存放在用户目录的 .ssh 子目录中。
2. 将公钥证书 id_rsa.pub 复制到机器B的root目录的.ssh子目录中,同时将文件名更换为authorized_keys。
[root@A root]# scp -