为了实现Centos之间自动从远程机器复制文件到本地,需要做如下配置操作:
认证设置:
1. 本地输入:ssh-keygen -t rsa
2. 输出Generating public/private rsa key pair.【回车】
Enterfile in which to save the key (/root/.ssh/id_rsa): 【回车】
Enterpassphrase (empty for no passphrase): 【回车】
Entersame passphrase again: 【回车】
Youridentification has been saved in /root/.ssh/id_rsa.
Yourpublic key has been saved in /root/.ssh/id_rsa.pub.
Thekey fingerprint is:
51:96:fd:d4:15:96:ba:11:3a:c3:1a:03:b9:dc:7a:20root@server-main1
The key's randomart image is:
+--[RSA 2048]----+
| . oo +=|
| o o. ..o..|
| . = . .oo |
| E + = = o. |
| . S + o o |
| . o . |
| . |
| |
| |
+-----------------+
生成黄色标记的2个文件
3. 将/root/.ssh/id_rsa.pub复制到远程机器/root/下
4. 远程机器执行:cat /root/id_rsa.pub > /root/.ssh/authorized_keys
提醒:如果之前已经存在authorized_keys文件,请将’>’换成追加符’>>’;双机互相认证自行思考。
自动复制:
1. 本地将scp命令写入/home/xxx.sh文档,需要有执行权限(chmod +x /home/xxx.sh)
2. 编辑/etc/crontab文档,加入命令10 08 * * */home/xxx.sh(每天8点10分执行一次)