Linux和windows之间使用scp无密码传输文件,脚本自动化

1、环境

windows2008 R2 和rhel 6.5

2、需求

通过在windows上指定计划任务,自动完成从Linux系统上备份文件到windows

3、工具

win:

  SSH Secure Shell Client         安装路径:D:\Program Files (x86)\SSH Communications Security

Linux:

  ssh -V
  OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010

 

4、脚本

cd D:\Program Files (x86)\SSH Communications Security\SSH Secure Shell\
scp2.exe root@192.168.10.168:/home/oracle/db_baklog/* D:\backup\script\linux_dbbak_logs\
//将远程Linux系统中的数据库备份日志cp到win的相应目录下

5、配置登录不交互密码

首先要了解ssh免密码登录的原理:

操作:

1)在windows是上执行

执行生成密钥的命令:

dos执行:D:\SSHCommunications Security\SSH Secure Shell>ssh-keygen2 -t  rsa

遇到输入一路回车,返回生成秘钥的位置

2)将生成的id_rsa_2048_a.pub复制到Linux的.ssh/目录下

 如果是Linux之间信任关系,就直接将公钥的内容追加到authorized_keys文件中即可。但是这里因为我们的公钥是在Windows上面生成的,Linux的Openssh不识别,所以需要进行转换后再追加到authorized_keys中:

[root@ggfwdb1 .ssh]# ssh-keygen -i -f id_rsa_2048_a.pub >>authorized_keys

到此,可以测试无密码cp文件了,测试没问题可以添加到计划任务。

 

posted @ 2018-08-17 14:39  abm  阅读(9242)  评论(0编辑  收藏  举报