scp(secure copy)是基于ssh的安全拷贝命令,scp常用的参数如下:
-2:Forces scp to use protocol 2. #基于ssh协议2文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
-4:Forces scp to use IPv4 addresses only. #基于TCP/IP ipv4协议文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
-P:port #接端口号文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
-p:Preserves modification times, access times, and modes from the original file. #保持文件或者目录的最后一次修改时间、属性。文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
-r:Recursively copy entire directories. #递归整个目录文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
-v:Verbose mode. #debug模式文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
系统环境:
主服务器hostname:SSH-MASTER    #IP:192.168.199.171/24 Centos 6.4 2.6.32-358.el6.x86_64
辅服务器hostname:SSH-CLIENT-NO01    #192.168.199.172/24 Centos 6.4 2.6.32-358.el6.x86_64文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
试验过程:
		
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@localhost ~]# hostname SSH-MASTER [root@SSH-MASTER ~]# cd /tmp [root@SSH-MASTER tmp]# touch test.txt [root@SSH-MASTER tmp]# ll total 0 -rw-r--r--. 1 root root 0 Apr 19 20:56 test.txt [root@SSH-MASTER tmp]# scp -P22 test.txt root@192.168.199.172:/tmp    #将test.txt复制到主机为192.168.199.172的/tmp目录下 The authenticity of host '192.168.199.172 (192.168.199.172)' can't be established. RSA key fingerprint is 05:35:6b:f7:7b:81:c7:4a:27:27:34:e4:90:1c:5d:fc. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.199.172' (RSA) to the list of known hosts. root@192.168.199.172's password:  test.txt                                                                                            100%    0     0.0KB/s   00:00  [root@SSH-CLIENT-NO01 tmp]# ll total 0 -rw-r--r--. 1 root root 0 Apr 19 21:04 test.txt    #已经复制成功 [root@SSH-MASTER tmp]# chown byrd.byrd test.txt    #修改test所有者和组为byrd chown: invalid user: `byrd.byrd'    #没有这个user [root@SSH-MASTER tmp]# useradd byrd    #添加用户 [root@SSH-MASTER tmp]# chown byrd.byrd test.txt [root@SSH-MASTER tmp]# ll total 0 -rw-r--r--. 1 byrd byrd 0 Apr 19 20:56 test.txt [root@SSH-MASTER tmp]# scp -P22 test.txt root@192.168.199.172:/tmp root@192.168.199.172's password:  test.txt                                                                                            100%    0     0.0KB/s   00:00  [root@SSH-CLIENT-NO01 tmp]# ll total 0 -rw-r--r--. 1 root root 0 Apr 19 21:07 test.txt    #属性不包括用户组和用户哦!~ [root@SSH-MASTER tmp]# chmod 777 test.txt    #修改test.txt权限为777 [root@SSH-MASTER tmp]# scp -P22 -p test.txt root@192.168.199.172:/tmp root@192.168.199.172's password:  test.txt                                                                                            100%    0     0.0KB/s   00:00   [root@SSH-CLIENT-NO01 tmp]# ll total 0 -rwxrwxrwx. 1 root root 0 Apr 19 20:56 test.txt    #客户端权限为777 [root@SSH-MASTER tmp]# scp -P22 -p /etc root@192.168.199.172:/tmp    #拷贝/etc目录到199.172的/tmp目录下 root@192.168.199.172's password:  /etc: not a regular file    #不规则的文件,不是文件是目录,所以拒绝了 [root@SSH-MASTER tmp]# scp -P22 -rp /etc root@192.168.199.172:/tmp    #-r递归拷贝。 root@192.168.199.172's password:  K90network                                                                                          100% 6334     6.2KB/s   00:00     S25blk-availability                                                                                 100% 1340     1.3KB/s   00:00    [root@SSH-CLIENT-NO01 tmp]# ll total 4 drwxr-xr-x. 72 root root 4096 Apr 19 21:06 etc    #拷贝完成 -rwxrwxrwx.  1 root root    0 Apr 19 20:56 test.txt | 
ok,到此结束。主要参数实际上也没有几个吧?-P接端口,-p是文件属性,-r是递归。文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
申明:本文由BYRD原创(基于Centos6.4 X64),未经许可禁止转载!文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/ 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/ssh-secure-copy/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
 
							
