共计 5948 个字符,预计需要花费 15 分钟才能阅读完成。
昨日举荐: 每天学一个 Linux 命令(59):ssh
命令简介
scp 全拼 secure copy,用于不同主机之间复制文件。
scp 命令罕用于在 Linux 零碎下两个不同主机之间传输文件,其性能与 cp 命令类似,然而不同是,cp 命令只能用于在本机环境下传输或复制拷贝文件,scp 命令能够逾越不同主机,而 scp 传输文件是加密的。
scp 它应用 ssh 进行数据传输,并应用与 ssh 雷同的身份验证并提供雷同的安全性,scp 会要求输出明码或其它形式以进行身份验证。
语法格局
scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
- 源文件:须要复制的文件
- 指标文件:格局为 user@host:filename(文件名为指标文件的名称)
选项阐明
-1 #指定应用 ssh 协定版本为 1
-2 #指定应用 ssh 协定版本为 2
-3 #指定两个主机之间的正本通过本地主机传输
-4 #指定应用 ipv4
-6 #指定应用 ipv6
-B #应用批处理模式
-C #应用压缩模式传输文件
-F #应用指定的 ssh 配置文件
-i identity_file #从指定文件中读取传输时应用的密钥文件
-l #宽带限度
-o #应用的 ssh 选项
-P #近程主机的端口号
-p #保留文件的最初批改工夫,最初拜访工夫和权限模式
-q #不输入复制进度信息
-r #以递归形式复制
-S program #指定加密传输时所应用的程序
-v #显示传输过程的详细信息
利用举例
从近程服务器复制到本地服务器
# 复制文件
scp root@192.168.1.2:/download/soft/nginx.tar.gz /download/soft/
#复制目录
scp -r root@192.168.1.2:/app/soft/mongodb /app/soft/
以 mingongge 用户身份将近程主机 mingongge.com 上的 /home/mingongge/backup.tar.gz 文件传送到当前工作目录下,并将传输限度为每秒 80 KB
scp -l 80 mingongge@mingongge.com:/home/mingongge/backup.tar.gz
#也能够写成如下
scp -l 80 mingongge@mingongge.com:/home/mingongge/backup.tar.gz ./
应用指定的端口号传输文件
scp -P 9999 root@192.168.1.2:/download/soft/nginx.tar.gz /download/soft/
查看具体的传输过程
[root@centos7 ~]# scp -v root@192.168.1.100:/root/nginxWebUI-1.3.5.jar /root/download/
Executing: program /usr/bin/ssh host 192.168.1.100, user root, command scp -v -f /root/nginxWebUI-1.3.5.jar
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.1.100 [192.168.1.100] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
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.1.100: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: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> 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:GqOqgdhVZyEtg/wSM8l5YB+Y6GO8K3Ii7OFsKW9R2n0
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ECDSA key fingerprint is SHA256:GqOqgdhVZyEtg/wSM8l5YB+Y6GO8K3Ii7OFsKW9R2n0.
ECDSA key fingerprint is MD5:cc:4b:7d:b6:59:0f:77:83:a9:a5:32:70:4e:87:0d:41.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.100' (ECDSA) to the list of known hosts.
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=<rsa-sha2-256,rsa-sha2-512>
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: Trying private key: /root/.ssh/id_rsa
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.1.100's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.1.100 ([192.168.1.100]: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 -f /root/nginxWebUI-1.3.5.jar
Sending file modes: C0644 36196329 nginxWebUI-1.3.5.jar
Sink: C0644 36196329 nginxWebUI-1.3.5.jar
nginxWebUI-1.3.5.jar 100% 35MB 12.1MB/s 00:02
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 12604, received 36237992 bytes, in 4.3 seconds
Bytes per second: sent 2916.1, received 8384212.5
debug1: Exit status 0
通过上述过程信息,能够晓得 scp 传输文件的整个过程是什么样的,也能够明确一些原理。
每天学一个 Linux 命令(57):cal
每天学一个 Linux 命令(58):telnet
正文完