Linux命令(125)之scp

简介: Linux命令(125)之scp

linux命令之scp

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

2.scp用法
scp [参数]

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

scp 192.168.10.249.txt root@192.168.10.244:/root/

[root@rhel77 ~]# scp 192.168.10.249.txt root@192.168.10.244:/root/
root@192.168.10.244's password:
192.168.10.249.txt 100% 60 51.7KB/s 00:00
[root@rhel77 ~]#
[root@logstash ~]# ls -l 192.168.10.249.txt
-rw-r--r-- 1 root root 60 Nov 17 08:44 192.168.10.249.txt
[root@logstash ~]# cat 192.168.10.249.txt
192.168.10.249
192.168.10.249
192.168.10.249
192.168.10.249
[root@logstash ~]#
3.2.复制目录至远程主机
命令:

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

[root@rhel77 ~]# scp -prqv /root/ztj.bak/ root@192.168.10.244:/root/
Executing: program /usr/bin/ssh host 192.168.10.244, user root, command scp -v -r -p -t /root/
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for
debug1: Connecting to 192.168.10.244 [192.168.10.244] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH
compat 0x04000000
debug1: Authenticating to 192.168.10.244:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:EADmS0F6cqxJ00yk8pc9FgPizA/kfgBDdJTOnzrLX6Q
debug1: Host '192.168.10.244' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password
root@192.168.10.244's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.10.244 ([192.168.10.244]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -r -p -t /root/
File mtime 1699619416 atime 1700181824
Sending file timestamps: T1699619416 0 1700181824 0
Sink: T1699619416 0 1700181824 0
Entering directory: D0777 0 ztj.bak
Sink: D0777 0 ztj.bak
File mtime 1699407457 atime 1699619299
Sending file timestamps: T1699407457 0 1699619299 0
Sink: T1699407457 0 1699619299 0
Sending file modes: C0644 11 ztj-2.txt
Sink: C0644 11 ztj-2.txt
File mtime 1699407510 atime 1699619297
Sending file timestamps: T1699407510 0 1699619297 0
Sink: T1699407510 0 1699619297 0
Sending file modes: C0644 10 ztj-1.txt
Sink: C0644 10 ztj-1.txt
File mtime 1699619079 atime 1699619100
Sending file timestamps: T1699619079 0 1699619100 0
Sink: T1699619079 0 1699619100 0
Sending file modes: C0755 26 test.sh
Sink: C0755 26 test.sh
Sink: E
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 2836, received 3168 bytes, in 0.1 seconds
Bytes per second: sent 36610.1, received 40895.9
debug1: Exit status 0
[root@rhel77 ~]#

[root@logstash ~]# ls -ld ztj.bak/
drwxrwxrwx 2 root root 55 Nov 10 20:30 ztj.bak/
[root@logstash ~]# cd ztj.bak/
[root@logstash ztj.bak]# ll
total 12
-rwxr-xr-x 1 root root 26 Nov 10 20:24 test.sh
-rw-r--r-- 1 root root 10 Nov 8 09:38 ztj-1.txt
-rw-r--r-- 1 root root 11 Nov 8 09:37 ztj-2.txt

————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/134454496

目录
相关文章
|
1月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
110 8
|
1月前
|
监控 Linux
如何检查 Linux 内存使用量是否耗尽?这 5 个命令堪称绝了!
本文介绍了在Linux系统中检查内存使用情况的5个常用命令:`free`、`top`、`vmstat`、`pidstat` 和 `/proc/meminfo` 文件,帮助用户准确监控内存状态,确保系统稳定运行。
410 6
|
1月前
|
Linux
在 Linux 系统中,“cd”命令用于切换当前工作目录
在 Linux 系统中,“cd”命令用于切换当前工作目录。本文详细介绍了“cd”命令的基本用法和常见技巧,包括使用“.”、“..”、“~”、绝对路径和相对路径,以及快速切换到上一次工作目录等。此外,还探讨了高级技巧,如使用通配符、结合其他命令、在脚本中使用,以及实际应用案例,帮助读者提高工作效率。
93 3
|
1月前
|
监控 安全 Linux
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景,包括 ping(测试连通性)、traceroute(跟踪路由路径)、netstat(显示网络连接信息)、nmap(网络扫描)、ifconfig 和 ip(网络接口配置)。掌握这些命令有助于高效诊断和解决网络问题,保障网络稳定运行。
81 2
|
22天前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
50 14
Linux 10 个“who”命令示例
|
2天前
|
Linux
linux查看目录下的文件夹命令,find查找某个目录,但是不包括这个目录本身?
通过本文的介绍,您应该对如何在 Linux 系统中查看目录下的文件夹以及使用 `find` 命令查找特定目录内容并排除该目录本身有了清晰的理解。掌握这些命令和技巧,可以大大提高日常文件管理和查找操作的效率。 在实际应用中,灵活使用这些命令和参数,可以帮助您快速定位和管理文件和目录,满足各种复杂的文件系统操作需求。
22 8
|
11天前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
90 20
|
11天前
|
网络协议 Linux 应用服务中间件
kali的常用命令汇总Linux
kali的常用命令汇总linux
35 7
|
1月前
|
Linux 数据库
Linux中第一次使用locate命令报错?????
在Linux CentOS7系统中,使用`locate`命令时出现“command not found”错误,原因是缺少`mlocate`包。解决方法是通过`yum install mlocate -y`或`apt-get install mlocate`安装该包,并执行`updatedb`更新数据库以解决后续的“can not stat”错误。
34 9
|
29天前
|
监控 网络协议 Linux
Linux netstat 命令详解
Linux netstat 命令详解