在shell中使用scp拷贝文件会涉及输入密码的问题,可以使用sshkey在主机之间建立信任
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。
scp ~/.ssh/id_rsa.pub 192.168.18.13:/root/.ssh/authorized_keys
这里可能会出现问题:
[root@localhost ~]# scp .ssh/id_rsa.pub 192.168.18.12:/root/.ssh/authorized_keys
The authenticity of host '192.168.18.12 (192.168.18.12)' can't be established.
RSA key fingerprint is f9:26:dd:fa:7b:84:76:77:fe:07:f9:f3:8c:f5:72:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.18.12' (RSA) to the list of known hosts.
root@192.168.18.12's password:
bash: scp: command not found
lost connection
可以这样解决:
yum install openssh-clients
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。
scp ~/.ssh/id_rsa.pub 192.168.18.13:/root/.ssh/authorized_keys
这里可能会出现问题:
[root@localhost ~]# scp .ssh/id_rsa.pub 192.168.18.12:/root/.ssh/authorized_keys
The authenticity of host '192.168.18.12 (192.168.18.12)' can't be established.
RSA key fingerprint is f9:26:dd:fa:7b:84:76:77:fe:07:f9:f3:8c:f5:72:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.18.12' (RSA) to the list of known hosts.
root@192.168.18.12's password:
bash: scp: command not found
lost connection
可以这样解决:
yum install openssh-clients