zoukankan      html  css  js  c++  java
  • 使用openssh-clients的scp命令来传输文件

    了解openssh-client是请参阅:https://blog.csdn.net/u010215256/article/details/53239905

    了解scp命令来传输文件请参阅:https://blog.csdn.net/sukhoi27smk/article/details/19990439

    声明:版权属于原作者,感谢两位整理

    一. openssh-clients(参考:https://blog.csdn.net/u010215256/article/details/53239905)

    之前因为需要搭建hadoop的集群,会用到ssh的功能。我的linux版本为centos6.4的minimal版本,虽然Windows环境下可以用XShell工具连上centos,但是centos之间去不能使用ssh登录。
    • openssh-server的功能主要是作为一个服务运行在后台,如果这个服务开启,我们就可以用一些远程连接工具来连接centos。因为minimal版本自带openssh-server,所以XShell可以连上centos

    • openssh-client的功能我觉得类似于XShell,可以作为一个客户端连接上openssh-server,但是Centos6.4的minimal版本不包括openssh-client,所以centos之前出现无法使用ssh登录的情况,centos可以使用如下命令安装客户端:

    1 安装wget
    2 yum -y install wget
    3 
    4 安装openssh-client
    5 yum install openssh-clients
    • Ubuntu下可以使用如下命令openssh的服务端和客户端(好像安装openssh-server时也会自动安装openssh-clients)
    1 sudo apt-get update
    2 sudo apt-get install openssh-server

     我自己看过后的理解:

    openssh-client和openssh-server就是一个客户端,一个服务端,两者连接后,我们可以通过他们再两台机器(或者说两个linux系统)之间传递文件等,一般情况,linux系统会自带
    openssh-server,作为后台服务在运行,因此我们可以在windows系统上通过工具xshell连接上linux系统,此时xshell相当于openssh-client,连接上了linux系统上的openssh-server,
    但是当我们在两个linux系统之间传递文件时,就需要使用openssh-client和openssh-server,openssh-client没有安装的话需要安装,然后通过他的scp命令来传递文件。scp命令传递文件的
    用法可参考文章开头的第二个网址。

    二. scp命令(参考:https://blog.csdn.net/sukhoi27smk/article/details/19990439)

      系统环境:RedHat Enterprise Linux Server 6

      主机desktop作为客户端,服务器为9.9.9.9(域名为www.huage.com)

      以下4个实例均在客户端完成,此时并未通过ssh登录到www.huage.com

      1、复制远程服务器的文件到本地:

      [root@desktop huage]#scp -P 22 root@9.9.9.9:/etc/yum.conf /home/huage/tmp/

      将远程服务器上的/etc/yum.conf文件拷贝到本机的/home/huage/tmp/目录

      2、复制远程服务器的目录到本地:

      [root@desktop huage]#scp -vrp -P 22 root@9.9.9.9:/sony/home/huage/

      将远程服务器上的目录/sony/拷贝到本机的/home/huage/目录

      3、复制本地的文件到远程服务器:

      [root@desktop huage]#scp -P 22 /home/huage/001 root@9.9.9.9:/home/

      将本机的/home/huage/001文件拷贝到服务器的/home/目录

      4、复制本地的目录到远程服务器:

      [root@desktop huage]#scp -vrp -P 22 /home/huage/tmp/ root@9.9.9.9:/home/

      将本机的/home/huage/tmp/目录拷贝到服务器的/home/目录

      scp用法:

      -P prot(后接SSH端口,默认为22)

      -v verbose(显示详细的传输过程)

      -r recursion (递归,用于传输目录及其子目录)

      -p Preserves modification times, access times, andmodes from the original file.

      保持源文件的所有属性

      注:root@9.9.9.9表示以root用户登录9.9.9.9

  • 相关阅读:
    inline函数
    STL——萃取机制(Traits)
    linux下静态库和动态库的制作与使用
    TCP连接(client、server)状态转换
    构造、拷贝构造、赋值、析构
    python数据类型分类
    考研结束,重返python
    使用Pyquery+selenium抓取淘宝商品信息
    python + Jquery,抓取西东网上的Java教程资源网址
    自定义元类控制类的实例化行为
  • 原文地址:https://www.cnblogs.com/tjudzj/p/9306525.html
Copyright © 2011-2022 走看看