使用openssh-clients的scp命令来传输文件

使用openssh-clients的scp命令来传输文件,第1张

使用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可以使用如下命令安装客户端:

 安装wget
yum -y install wget 安装openssh-client
yum install openssh-clients
  • Ubuntu下可以使用如下命令openssh的服务端和客户端(好像安装openssh-server时也会自动安装openssh-clients)
 sudo apt-get update
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 [email protected]:/etc/yum.conf /home/huage/tmp/

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

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

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

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

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

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

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

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

  [root@desktop huage]#scp -vrp -P 22 /home/huage/tmp/ [email protected]:/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.

  保持源文件的所有属性

  注:[email protected]表示以root用户登录9.9.9.9

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/586370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存