今天我就来和大家聊聊如何在linux中使用scp命令,这个可能很多人都不太懂。为了让大家更好的了解,本站为大家总结了以下内容。希望大家能从这篇文章中有所收获。
1.命令格式:
scp[参数][原始路径][目标路径]
2.命令功能:
Scp是安全复制的缩写,scp是linux系统中基于ssh登录的安全远程文件复制命令。linux scp命令可以在Linux服务器之间复制文件和目录
3.命令参数:
-1强制scp命令使用ssh2协议
-2强制scp命令使用ssh3协议
-4强制scp命令仅使用IPv4寻址
-6强制scp命令仅使用IPv6寻址
-B使用批量模式(传输过程中不询问传输密码或短语)
-C允许压缩。(将-C标志传递给ssh以打开压缩功能)
-p保留原文件的修改时间、访问时间和访问权限。
-q不显示传输进度条。
-r递归复制整个目录。
-v详细显示输出。Scp和ssh(1)会显示整个过程的调试信息。此信息用于调试连接、身份验证和配置问题。
-c cipher用cipher加密数据传输,这个选项会直接传递给ssh。
-F ssh_config指定一个替代的ssh配置文件,这个参数直接传递给ssh。
-i identity_file从指定的文件中读取用于传输的密钥文件,并将该参数直接传递给ssh。
-l limit限制用户可以使用的Kbit/s带宽.
-o ssh_option如果您习惯ssh_config(5)中的参数传递方法,
-P端口注意是大写的P,port是用来指定数据传输的端口号
-S程序指定加密传输时使用的程序。这个程序必须能够理解ssh(1)的选项。
4.举例说明:
scp命令实际应用综述:
从本地服务活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看器复制到远程服务器:
(1)复制文件:
命令格式:
代码如下:
scp local _ file a href=\’ mailto : remote _ username @ remote _ IP : remote _ folder \’ remote _ username @ remote _ IP : remote _ folder/a
或者
scp local _ file a href=\’ mailto : remote _ username @ remote _ IP : remote _ file \’ remote _ username @ remote _ IP : remote _ file/a
或者
scp本地_文件远程_ IP :远程_文件夹
或者
scp local _ file remote _ IP : remote _ file
第一个和第二个指定用户名,执行命令后需要输入用户密码。第一个只指定远程目录,文件名保持不变,第二个指定文件名
第3和第4行没有指定用户名,在命令执行后需要输入用户名和密码。第三个只指定远程目录,文件名保持不变,第四个指定文件名
(2)复制目录:
命令格式:
scp-r local _ folder remote _用户名@remote_ip:remote_folder
或者
scp-r local _ folder remote _ IP : remote _ folder
第一个指定用户名,执行命令后需要输入用户密码;
第二个没有指定用户名,需要在命令执行后输入用户名和密码;
从远程服务器复制到本地服务器:
从远程复制到本地的scp命令类似于上面的命令,只要从本地复制到远程的命令后面的两个参数按顺序互换。
示例1:将文件从远程位置复制到本地目录
命令:scp lot @ 192 . 168 . 120 . 204:/opt/soft/nginx-0 . 5 . 38 . tar . gz/opt/soft/
输出:
代码如下:
[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# ll
总计80072
drwxr-xr-x 12 root 4096 09-21 18:40 FMS 3.5
drwxr-xr-x 3根根4096 09-21 17:58 fms4.5
drwxr-xr-x 10 root 4096 10-30 17:15 JDK 1 . 6 . 0 _ 16
drwxr-xr-x 10 root 4096 09-17 19:27 JDK 1 . 6 . 0 _ 16 . bak
-rwxr-xr-x 1根根81871260 200
9-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root root 4096 09-21 01:16 mysqldrwxr-xr-x 3 root root 4096 09-21 18:40 setup_filedrwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0[root@localhost soft]# scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/root@192.168.120.204\’s password: nginx-0.5.38.tar.gz 100% 479KB 478.7KB/s 00:00 [root@localhost soft]# ll总计 80556drwxr-xr-x 12 root root 4096 09-21 18:40 fms3.5drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5drwxr-xr-x 10 root root 4096 10-30 17:15 jdk1.6.0_16drwxr-xr-x 10 root root 4096 09-17 19:27 jdk1.6.0_16.bak-rwxr-xr-x 1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root root 4096 09-21 01:16 mysql-rw-r–r– 1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root root 4096 09-21 18:40 setup_filedrwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0[root@localhost soft]#
说明:从192.168.120.204机器上的/opt/soft/的目录中下载nginx-0.5.38.tar.gz 文件到本地/opt/soft/目录中
实例2:从远处复制到本地命令:scp -r root@192.168.120.204:/opt/soft/mongodb /opt/soft/输出:
代码如下:
[root@localhost soft]# ll总计 80556drwxr-xr-x 12 root root 4096 09-21 18:40 fms3.5drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5drwxr-xr-x 10 root root 4096 10-30 17:15 jdk1.6.0_16drwxr-xr-x 10 root root 4096 09-17 19:27 jdk1.6.0_16.bak-rwxr-xr-x 1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxrwxrwx 2 root root 4096 09-21 01:16 mysql-rw-r–r– 1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root root 4096 09-21 18:40 setup_filedrwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0[root@localhost soft]# scp -r root@192.168.120.204:/opt/soft/mongodb /opt/soft/root@192.168.120.204\’s password: mongodb-linux-i686-static-1.8.5.tgz 100% 28MB 28.3MB/s 00:01 README 100% 731 0.7KB/s 00:00 THIRD-PARTY-NOTICES 100% 7866 7.7KB/s 00:00 mongorestore 100% 7753KB 7.6MB/s 00:00 mongod 100% 7760KB 7.6MB/s 00:01 mongoexport 100% 7744KB 7.6MB/s 00:00 bsondump 100% 7737KB 7.6MB/s 00:00 mongofiles 100% 7748KB 7.6MB/s 00:01 mongostat 100% 7808KB 7.6MB/s 00:00 mongos 100% 5262KB 5.1MB/s 00:01 mongo 100% 3707KB 3.6MB/s 00:00 mongoimport 100% 7754KB 7.6MB/s 00:00 mongodump 100% 7773KB 7.6MB/s 00:00 GNU-AGPL-3.0 100% 34KB 33.7KB/s 00:00 [root@localhost soft]# ll总计 80560drwxr-xr-x 12 root root 4096 09-21 18:40 fms3.5drwxr-xr-x 3 root root 4096 09-21 17:58 fms4.5drwxr-xr-x 10 root root 4096 10-30 17:15 jdk1.6.0_16drwxr-xr-x 10 root root 4096 09-17 19:27 jdk1.6.0_16.bak-rwxr-xr-x 1 root root 81871260 2009-12-21 jdk-6u16-linux-x64.bindrwxr-xr-x 3 root root 4096 03-15 09:18 mongodbdrwxrwxrwx 2 root root 4096 09-21 01:16 mysql-rw-r–r– 1 root root 490220 03-15 09:11 nginx-0.5.38.tar.gzdrwxr-xr-x 3 root root 4096 09-21 18:40 setup_filedrwxr-xr-x 9 root root 4096 09-17 19:23 tomcat6.0.32drwxr-xr-x 9 root root 4096 2012-08-14 tomcat_7.0[root@localhost soft]#
说明:从192.168.120.204机器上的/opt/soft/中下载mongodb 目录到本地的/opt/soft/目录来。
实例3:上传本地文件到远程机器指定目录命令:scp /opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptest输出:
代码如下:
上传前目标机器的目标目录:[root@localhost soft]# cd scptest/[root@localhost scptest]# ll总计 0[root@localhost scptest]# ll
本地机器上传:[root@localhost soft]# scp /opt/soft/nginx-0.5.38.tar.gz root@192.168.120.204:/opt/soft/scptestroot@192.168.120.204\’s password: nginx-0.5.38.tar.gz 100% 479KB 478.7KB/s 00:00 [root@localhost soft]#
上传后目标机器的目标目录:[root@localhost scptest]# ll总计 484-rw-r–r– 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz[root@localhost scptest]#
说明:复制本地opt/soft/目录下的文件nginx-0.5.38.tar.gz 到远程机器192.168.120.204的opt/soft/scptest目录
实例4:上传本地目录到远程机器指定目录命令:scp -r /opt/soft/mongodb root@192.168.120.204:/opt/soft/scptest输出:
代码如下:
上传前目标机器的目标目录:[root@localhost ~]# cd /opt/soft/scptest/[root@localhost scptest]# ll总计 484-rw-r–r– 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz[root@localhost scptest]# 本地机器上传:[root@localhost ~]# scp -r /opt/soft/mongodb root@192.168.120.204:/opt/soft/scptestroot@192.168.120.204\’s password: mongodb-linux-i686-static-1.8.5.tgz 100% 28MB 28.3MB/s 00:01 README 100% 731 0.7KB/s 00:00 THIRD-PARTY-NOTICES 100% 7866 7.7KB/s 00:00 mongorestore 100% 7753KB 7.6MB/s 00:00 mongod 100% 7760KB 7.6MB/s 00:01 mongoexport 100% 7744KB 7.6MB/s 00:00 bsondump 100% 7737KB 7.6MB/s 00:00 mongofiles 100% 7748KB 7.6MB/s 00:00 mongostat 100% 7808KB 7.6MB/s 00:01 mongos 100% 5262KB 5.1MB/s 00:00 mongo 100% 3707KB 3.6MB/s 00:00 mongoimport 100% 7754KB 7.6MB/s 00:01 mongodump 100% 7773KB 7.6MB/s 00:00 GNU-AGPL-3.0 100% 34KB 33.7KB/s 00:00 [root@localhost ~]#
上传后目标机器的目标目录:[root@localhost scptest]# ll总计 488drwxr-xr-x 3 root root 4096 03-15 09:33 mongodb-rw-r–r– 1 root root 490220 03-15 09:25 nginx-0.5.38.tar.gz[root@localhost scptest]#
看完上述内容,你们对怎么在linux中使用scp命令有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
《怎么在linux中使用scp命令》来自互联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...