linux 两服务器之间的文件传输scp

Linux scp 命令用于 Linux 之间复制文件和目录。

scp 是 secure copy 的缩写, scp 是 linux 系统下基于 ssh 登陆进行安全的远程文件拷贝命令。

scp 是加密的,rcp 是不加密的,scp 是 rcp 的加强版。肯定建议加密好一些

常用方法介绍:

本地文件复制到远程主机:
scp local_file user@host:/dir
scp -P 16022 local_file user@host:/dir #ssh的端口不是默认的端口要指定!

远程文件复制到本机:
scp  user@host:/dir  local_file


如果是目录,需要加上-r 参数

 说明:

-a 尽可能将档案状态、权限等资料都照原状予以复制
-r 若 source 中含有目录名,则将目录下之档案亦皆依序拷贝至目的地
-f 若目的地已经有相同档名的档案存在,则在复制前先予以删除再行复制
-v 和大多数 linux 命令中的 -v 意思一样 , 用来显示进度 . 可以用来查看连接 , 认证 , 或是配置错误
-C 使能压缩选项
-P 选择端口 . 注意 -p 已经被 rcp 使用
-4 强行使用 IPV4 地址
-6 强行使用 IPV6 地址

复制

[[email protected] ~]$touch ab
[[email protected] ~]$scp -P 20042 ab  apps@192.168.111.153:/tmp
The authenticity of host '[192.168.111.153]:20042 ([192.168.111.153]:20042)' can't be established.
RSA key fingerprint is 3c:ff:51:9e:3c:cc:dd:66:42:f1:49:09:4f:5c:a0:96.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.111.153]:20042' (RSA) to the list of known hosts.
apps@192.168.111.153's password: 
ab                                                                   100%    0     0.0KB/s   00:00   

检测:

[[email protected] ~]$cd /tmp/
[[email protected] tmp]$ls
90-nproc.conf.20200207  limits.conf.20200207  yum_save_tx-2020-02-18-09-20YQ6Wj3.yumtx
ab                      sysctl.conf.20200207
Initialize.quan.sh      yum.log

注意:客户端和服务端都是要安装scp命令包的

否则出现下面的情况:

[[email protected] ~]$scp -P 20042 ab  apps@192.168.111.152:/tmp
The authenticity of host '[192.168.111.152]:20042 ([192.168.111.152]:20042)' can't be established.
RSA key fingerprint is 3c:ff:51:9e:3c:cc:dd:66:42:f1:49:09:4f:5c:a0:96.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.111.152]:20042' (RSA) to the list of known hosts.
apps@192.168.111.152's password: 
bash: scp: command not found
lost connection

猜你喜欢

转载自www.cnblogs.com/betterquan/p/12334660.html