zoukankan      html  css  js  c++  java
  • ubuntu下scp批量拷贝文件不需输入密码

    scpsecure copy的缩写,scplinux系统下基于ssh登录进行安全的远程文件拷贝命令。

    Linuxscp命令可以在linux服务器之间复制文件和目录。

    scp命令的用处:

    scp在网络上不同的主机之间复制文件,它使用ssh安全协议传输数据,具有和ssh一样的验证机制,从而安全的远程拷贝文件。

    scp命令的基本格式:

    scp[-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]

    [-llimit] [-o ssh_option] [-P port] [-S program]

    [[user@]host1:]file1[……] [[user@]host2:]file2

    scp命令的参数说明:

    -1

    强制scp命令使用协议ssh1

    -2

    强制scp命令使用协议ssh2

    -4

    强制scp命令使用协议IPv4寻址

    -6

    强制scp命令使用IPv6寻址

    -B

    使用批处理模式(传输过程中不询问传输口令或短语)

    -C

    允许压缩

    -p

    保留原文件的修改时间,访问时间和访问权限

    -q

    不显示传输进度条

    -r

    递归复制整个目录

    -v

    详细方式显示输出。Scpssh会显示整个过程的调试信息。

    -c cipher

    cipher将数据传输进行加密。

    -F ssh_config

    指定一个替代的ssh配置文件

    -i identity_file

    从指定文件中读取传输时使用的密钥文件

    -l limit

    限定用户所能使用的带宽

    -o ssh_option

    如果习惯使用ssh_config中的参数传递方式

    -P port

    port是指定传输用到的端口号

    -S program

    制定加密传输时所使用的程序。


    scp的实际应用

    1>从本地复制到远程主机

    scp local_file remote_username@remote_ip:remote_folder

    或者

    scp local_file remote_username@remote_ip:remote_file

    或者

    scp local_file remote_ip:remote_folder(remote_file)

    2>复制目录

    scp -r local_folder remote_username@remote_ip:remote_folder

    或者

    scp -r local_folder remote_ip:remote_folder

    3>从远程主机到本机

    scp remote_username@remote_ip:remote_file local_file


    两台机子,本机A(user1机子上),B.每次scp B:/home/user,都需要密码,很是麻烦,做如下操作:

    在机子A:

         [user1@rhuser1]$ ssh-keygen -trsa(下面的是提示信息,目的是为了不想有密码,则可全部按enter,一直到最后)
      Generatingpublic/private rsa key pair.
      Enterfile in which to save the key (/home/user1/.ssh/id_rsa):
      Createddirectory '/home/user1/.ssh'.
      Enterpassphrase (empty for no passphrase):
      Entersame passphrase again:
      Youridentification has been saved in /home/user1/.ssh/id_rsa.
      Yourpublic key has been saved in /home/user1/.ssh/id_rsa.pub.
      Thekey fingerprintis:
      e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com

    修改一下.ssh目录的权限,使用命令"chmod755 ~/.ssh"

    之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
    ~/.ssh/authorized_keys.

          [user1@rhuser1]$ scp ~/.ssh/id_rsa.pubrh1:/home/user1/.ssh/authorized_keys
      user1@rh1'spassword:
      id_rsa.pub100% 228 3.2MB/s 00:00

    结束之后,A上再用scp命令,则不用输入密码了,呵呵

  • 相关阅读:
    poj3126--Prime Path(广搜)
    iOS中 imageNamed方法 非常多图片占用大量内存问题
    容器+AOP实现动态部署(四)
    SpringBoot整合redis哨兵主从服务
    LINUX安装REDIS集群
    软件安装
    如何优雅地用Redis实现分布式锁
    Redis面试总结
    OAuth2.0 知多少(好)
    一张图搞定OAuth2.0
  • 原文地址:https://www.cnblogs.com/chengliu/p/3636366.html
Copyright © 2011-2022 走看看