昨日举荐:每天学一个 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.jarOpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /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/0debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_rsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_rsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_dsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_dsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ecdsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ecdsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ed25519 type -1debug1: key_load_public: No such file or directorydebug1: identity file /root/.ssh/id_ed25519-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_7.4debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000debug1: Authenticating to 192.168.1.100:22 as 'root'debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: algorithm: curve25519-sha256debug1: kex: host key algorithm: ecdsa-sha2-nistp256debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: nonedebug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: nonedebug1: kex: curve25519-sha256 need=64 dh_need=64debug1: kex: curve25519-sha256 need=64 dh_need=64debug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug1: Server host key: ecdsa-sha2-nistp256 SHA256:GqOqgdhVZyEtg/wSM8l5YB+Y6GO8K3Ii7OFsKW9R2n0The 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)? yesWarning: Permanently added '192.168.1.100' (ECDSA) to the list of known hosts.debug1: rekey after 134217728 blocksdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: rekey after 134217728 blocksdebug1: SSH2_MSG_EXT_INFO receiveddebug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>debug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,passworddebug1: Next authentication method: gssapi-keyexdebug1: No valid Key exchange contextdebug1: Next authentication method: gssapi-with-micdebug1: Unspecified GSS failure. Minor code may provide more informationNo Kerberos credentials available (default cache: KEYRING:persistent:0)debug1: Unspecified GSS failure. Minor code may provide more informationNo Kerberos credentials available (default cache: KEYRING:persistent:0)debug1: Next authentication method: publickeydebug1: Trying private key: /root/.ssh/id_rsadebug1: Trying private key: /root/.ssh/id_dsadebug1: Trying private key: /root/.ssh/id_ecdsadebug1: Trying private key: /root/.ssh/id_ed25519debug1: Next authentication method: passwordroot@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.comdebug1: Entering interactive session.debug1: pledge: networkdebug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0debug1: Sending environment.debug1: Sending env LANG = en_US.UTF-8debug1: Sending command: scp -v -f /root/nginxWebUI-1.3.5.jarSending file modes: C0644 36196329 nginxWebUI-1.3.5.jarSink: C0644 36196329 nginxWebUI-1.3.5.jarnginxWebUI-1.3.5.jar 100% 35MB 12.1MB/s 00:02 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0debug1: channel 0: free: client-session, nchannels 1debug1: fd 0 clearing O_NONBLOCKdebug1: fd 1 clearing O_NONBLOCKTransferred: sent 12604, received 36237992 bytes, in 4.3 secondsBytes per second: sent 2916.1, received 8384212.5debug1: Exit status 0
通过上述过程信息,能够晓得scp传输文件的整个过程是什么样的,也能够明确一些原理。
每天学一个 Linux 命令(57):cal
每天学一个 Linux 命令(58):telnet