• Linux命令(125)之scp


    linux命令之scp

    1.scp介绍

    linux命令scp用于在两个主机之间安全的复制文件和目录

    2.scp用法

    scp [参数]

    scp常用参数
    参数说明
    -P指定远程主机的端口
    -p复制文件时,保留原始文件的属性(E
    1. [root@rhel77 ~]# scp 192.168.10.249.txt root@192.168.10.244:/root/
    2. root@192.168.10.244's password:
    3. 192.168.10.249.txt 100% 60 51.7KB/s 00:00
    4. [root@rhel77 ~]#
    .g:修改次数、访问次数和模式、创建时间等)
    -r递归复制整个目录
    -q静默传输模式
    -v输出详细信息

    3.实例

    3.1.复制本地文件至远程主机

    命令:

    scp 192.168.10.249.txt root@192.168.10.244:/root/

    1. [root@rhel77 ~]# scp 192.168.10.249.txt root@192.168.10.244:/root/
    2. root@192.168.10.244's password:
    3. 192.168.10.249.txt 100% 60 51.7KB/s 00:00
    4. [root@rhel77 ~]#
    1. [root@logstash ~]# ls -l 192.168.10.249.txt
    2. -rw-r--r-- 1 root root 60 Nov 17 08:44 192.168.10.249.txt
    3. [root@logstash ~]# cat 192.168.10.249.txt
    4. 192.168.10.249
    5. 192.168.10.249
    6. 192.168.10.249
    7. 192.168.10.249
    8. [root@logstash ~]#

    3.2.复制目录至远程主机

    命令:

    scp -prqv /root/ztj.bak/ root@192.168.10.244:/root/

    1. [root@rhel77 ~]# scp -prqv /root/ztj.bak/ root@192.168.10.244:/root/
    2. Executing: program /usr/bin/ssh host 192.168.10.244, user root, command scp -v -r -p -t /root/
    3. OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
    4. debug1: Reading configuration data /etc/ssh/ssh_config
    5. debug1: /etc/ssh/ssh_config line 58: Applying options for *
    6. debug1: Connecting to 192.168.10.244 [192.168.10.244] port 22.
    7. debug1: Connection established.
    8. debug1: permanently_set_uid: 0/0
    9. debug1: identity file /root/.ssh/id_rsa type 1
    10. debug1: key_load_public: No such file or directory
    11. debug1: identity file /root/.ssh/id_rsa-cert type -1
    12. debug1: key_load_public: No such file or directory
    13. debug1: identity file /root/.ssh/id_dsa type -1
    14. debug1: key_load_public: No such file or directory
    15. debug1: identity file /root/.ssh/id_dsa-cert type -1
    16. debug1: key_load_public: No such file or directory
    17. debug1: identity file /root/.ssh/id_ecdsa type -1
    18. debug1: key_load_public: No such file or directory
    19. debug1: identity file /root/.ssh/id_ecdsa-cert type -1
    20. debug1: key_load_public: No such file or directory
    21. debug1: identity file /root/.ssh/id_ed25519 type -1
    22. debug1: key_load_public: No such file or directory
    23. debug1: identity file /root/.ssh/id_ed25519-cert type -1
    24. debug1: Enabling compatibility mode for protocol 2.0
    25. debug1: Local version string SSH-2.0-OpenSSH_7.4
    26. debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
    27. debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
    28. debug1: Authenticating to 192.168.10.244:22 as 'root'
    29. debug1: SSH2_MSG_KEXINIT sent
    30. debug1: SSH2_MSG_KEXINIT received
    31. debug1: kex: algorithm: curve25519-sha256
    32. debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    33. debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    34. debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    35. debug1: kex: curve25519-sha256 need=64 dh_need=64
    36. debug1: kex: curve25519-sha256 need=64 dh_need=64
    37. debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    38. debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EADmS0F6cqxJ00yk8pc9FgPizA/kfgBDdJTOnzrLX6Q
    39. debug1: Host '192.168.10.244' is known and matches the ECDSA host key.
    40. debug1: Found key in /root/.ssh/known_hosts:2
    41. debug1: rekey after 134217728 blocks
    42. debug1: SSH2_MSG_NEWKEYS sent
    43. debug1: expecting SSH2_MSG_NEWKEYS
    44. debug1: SSH2_MSG_NEWKEYS received
    45. debug1: rekey after 134217728 blocks
    46. debug1: SSH2_MSG_EXT_INFO received
    47. debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
    48. debug1: SSH2_MSG_SERVICE_ACCEPT received
    49. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
    50. debug1: Next authentication method: gssapi-keyex
    51. debug1: No valid Key exchange context
    52. debug1: Next authentication method: gssapi-with-mic
    53. debug1: Unspecified GSS failure. Minor code may provide more information
    54. No Kerberos credentials available (default cache: KEYRING:persistent:0)
    55. debug1: Unspecified GSS failure. Minor code may provide more information
    56. No Kerberos credentials available (default cache: KEYRING:persistent:0)
    57. debug1: Next authentication method: publickey
    58. debug1: Offering RSA public key: /root/.ssh/id_rsa
    59. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
    60. debug1: Trying private key: /root/.ssh/id_dsa
    61. debug1: Trying private key: /root/.ssh/id_ecdsa
    62. debug1: Trying private key: /root/.ssh/id_ed25519
    63. debug1: Next authentication method: password
    64. root@192.168.10.244's password:
    65. debug1: Authentication succeeded (password).
    66. Authenticated to 192.168.10.244 ([192.168.10.244]:22).
    67. debug1: channel 0: new [client-session]
    68. debug1: Requesting no-more-sessions@openssh.com
    69. debug1: Entering interactive session.
    70. debug1: pledge: network
    71. debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
    72. debug1: Sending environment.
    73. debug1: Sending env LANG = en_US.UTF-8
    74. debug1: Sending command: scp -v -r -p -t /root/
    75. File mtime 1699619416 atime 1700181824
    76. Sending file timestamps: T1699619416 0 1700181824 0
    77. Sink: T1699619416 0 1700181824 0
    78. Entering directory: D0777 0 ztj.bak
    79. Sink: D0777 0 ztj.bak
    80. File mtime 1699407457 atime 1699619299
    81. Sending file timestamps: T1699407457 0 1699619299 0
    82. Sink: T1699407457 0 1699619299 0
    83. Sending file modes: C0644 11 ztj-2.txt
    84. Sink: C0644 11 ztj-2.txt
    85. File mtime 1699407510 atime 1699619297
    86. Sending file timestamps: T1699407510 0 1699619297 0
    87. Sink: T1699407510 0 1699619297 0
    88. Sending file modes: C0644 10 ztj-1.txt
    89. Sink: C0644 10 ztj-1.txt
    90. File mtime 1699619079 atime 1699619100
    91. Sending file timestamps: T1699619079 0 1699619100 0
    92. Sink: T1699619079 0 1699619100 0
    93. Sending file modes: C0755 26 test.sh
    94. Sink: C0755 26 test.sh
    95. Sink: E
    96. debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    97. debug1: channel 0: free: client-session, nchannels 1
    98. debug1: fd 0 clearing O_NONBLOCK
    99. debug1: fd 1 clearing O_NONBLOCK
    100. Transferred: sent 2836, received 3168 bytes, in 0.1 seconds
    101. Bytes per second: sent 36610.1, received 40895.9
    102. debug1: Exit status 0
    103. [root@rhel77 ~]#
    1. [root@logstash ~]# ls -ld ztj.bak/
    2. drwxrwxrwx 2 root root 55 Nov 10 20:30 ztj.bak/
    3. [root@logstash ~]# cd ztj.bak/
    4. [root@logstash ztj.bak]# ll
    5. total 12
    6. -rwxr-xr-x 1 root root 26 Nov 10 20:24 test.sh
    7. -rw-r--r-- 1 root root 10 Nov 8 09:38 ztj-1.txt
    8. -rw-r--r-- 1 root root 11 Nov 8 09:37 ztj-2.txt
    9. [root@logstash ztj.bak]#
  • 相关阅读:
    吴恩达机器学习-可选实验室:逻辑回归(Logistic Regression))
    十大常见排序算法详解(附Java代码实现和代码解析)
    驱动开发--自动创建节点udev机制的实现过程分析
    【开发随记】【提效】工作习惯那些事系列之五——任务处理
    网络安全法学习
    [PaddleSpeech 原神] 音色克隆之胡桃
    【iOS逆向与安全】好用的一套 TCP 类
    超详细全面 spring 复习总结笔记
    sql注入(其他)
    外汇天眼:美国中期选举共和党若大获全胜!美元未来走势不利
  • 原文地址:https://blog.csdn.net/z19861216/article/details/134454496