• scp远程拷贝文件免密办法


    方法一:基于公钥和私钥的信任办法

      ssh-keygen -t rsa  

    方法二:sshpass

    下载地址:http://sourceforge.net/projects/sshpass/

    yum -y install gcc

    tar xf sshpass-1.06.tar.gz

    ./configure 

    make && make install

    sshpass -p 密码 scp -r 1.txt root@10.1.1.1:/root 

    sshpass -f 存放密码的文件 scp -r 1.txt root@10.1.1.1:/root

    方法三:python脚本

    [root@localhost ~]# cat 1.py
    #!/usr/bin/env python
    import paramiko
    import os
    import datetime
    hostname='10.1.1.132'
    username='root'
    password='redhat'
    port=22
    local_dir='/tmp/'
    remote_dir='/tmp/test/'
    if __name__=="__main__":
    # try:
    t=paramiko.Transport((hostname,port))
    t.connect(username=username,password=password)
    sftp=paramiko.SFTPClient.from_transport(t)
    # files=sftp.listdir(dir_path)
    files=os.listdir(local_dir)
    for f in files:
    print ''
    print '#########################################'
    print 'Beginning to upload file %s ' % datetime.datetime.now()
    print 'Uploading file:',os.path.join(local_dir,f)

    # sftp.get(os.path.join(dir_path,f),os.path.join(local_path,f))
    sftp.put(os.path.join(local_dir,f),os.path.join(remote_dir,f))

    print 'Upload file success %s ' % datetime.datetime.now()
    print ''
    print '##########################################'

    #except Exception:
    # print "error!"
    t.close()

  • 相关阅读:
    Cesium中监听MOUSE_MOVE事件获取经纬度和高度
    CentOS系统重命名
    docker安装步骤
    nginx发布vue 项目
    解决git 本地代码与远程仓库冲突问题
    js通过className删除元素
    bootstrap treeview基本运用
    自定义组件模拟v-model
    使用a标签下载**.txt文件, 而不是直接打开
    mongoose 开源http库
  • 原文地址:https://www.cnblogs.com/yangxiaochu/p/6913533.html
Copyright © 2020-2023  润新知