zoukankan      html  css  js  c++  java
  • 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 SecuritySSH Secure Shell
    scp2.exe root@192.168.10.168:/home/oracle/db_baklog/* D:ackupscriptlinux_dbbak_logs
    //将远程Linux系统中的数据库备份日志cp到win的相应目录下

    5、配置登录不交互密码

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

    操作:

    1)在windows是上执行

    执行生成密钥的命令:

    dos执行:D:SSHCommunications SecuritySSH 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文件了,测试没问题可以添加到计划任务。

  • 相关阅读:
    函数模板
    c#使用多线程的几种方式示例详解
    C#中数组、ArrayList和List三者的区别
    c# Thread类
    IEnumerable和IEnumerator 详解
    C#执行CMD命令并接收返回结果的实现方法
    C# Process.Start()方法详解
    C#Json转Xml格式数据的方法
    sql存储过程
    SQL存储过程基础
  • 原文地址:https://www.cnblogs.com/-abm/p/9493199.html
Copyright © 2011-2022 走看看