scp 命令的基本語(yǔ)法
?
下面的命令將讀作?
copy source_file_name
進(jìn)入destination_folder
在destination_host
使用username account
。
>?scp?source_file_name?username@destination_host:destination_folder
里面有很多參數(shù)
scp
你可以使用的命令。以下是可能在日常使用中使用的參數(shù)。
使用-v參數(shù)提供 scp 進(jìn)程的詳細(xì)信息
基礎(chǔ)的
scp
不帶參數(shù)的命令將在后臺(tái)復(fù)制文件。除非該過(guò)程完成或出現(xiàn)某些錯(cuò)誤,否則用戶將看不到任何內(nèi)容。
你可以使用?
-v
?參數(shù)將調(diào)試信息打印到屏幕中。它可以幫助你調(diào)試連接、身份驗(yàn)證和配置問(wèn)題。
rumenz@local?$?scp?-v?Label.pdf?rumenz@192.168.1.110:.
輸出
復(fù)制文件時(shí) scp 顯示進(jìn)度
Executing:?program?/usr/bin/ssh?host?202.x.x.x,?user?mrarianto,?command?scp?-v?-t?.
OpenSSH_6.0p1?Debian-3,?OpenSSL?1.0.1c?10?May?2012
debug1:?Reading?configuration?data?/etc/ssh/ssh_config
debug1:?/etc/ssh/ssh_config?line?19:?Applying?options?for?*
debug1:?Connecting?to?202.x.x.x?[202.x.x.x]?port?22.
debug1:?Connection?established.
debug1:?Host?'202.x.x.x'?is?known?and?matches?the?RSA?host?key.
debug1:?Found?key?in?/home/pungki/.ssh/known_hosts:1
debug1:?ssh_rsa_verify:?signature?correct
debug1:?Next?authentication?method:?password
rumenz@202.x.x.x's?password:
debug1:?Authentication?succeeded?(password).
Authenticated?to?202.x.x.x?([202.x.x.x]:22).
Sending?file?modes:?C0770?3760348?Label.pdf
Sink:?C0770?3760348?Label.pdf
Label.pdf?100%?3672KB?136.0KB/s?00:27
Transferred:?sent?3766304,?received?3000?bytes,?in?65.2?seconds
Bytes?per?second:?sent?57766.4,?received?46.0
debug1:?Exit?status?0
提供原始文件的修改時(shí)間、訪問(wèn)時(shí)間和模式
-p
?參數(shù)將幫助你解決這個(gè)問(wèn)題。估計(jì)時(shí)間和連接速度將出現(xiàn)在屏幕上。
rumenz@local?$?scp?-p?Label.pdf?rumenz@192.168.1.110:.
輸出
scp 估計(jì)復(fù)制大文件所需的時(shí)間
>?rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?126.6KB/s?00:29
使用 -C 參數(shù)加快文件傳輸速度
可以加快文件傳輸速度的參數(shù)之一是?
-C
?范圍。這?-C
?參數(shù)將隨時(shí)隨地壓縮你的文件,獨(dú)特的是壓縮只發(fā)生在網(wǎng)絡(luò)中。當(dāng)文件到達(dá)目標(biāo)服務(wù)器時(shí),它將恢復(fù)到壓縮前的原始大小。
>?rumenz@local?$?scp?-pv?messages.log?rumenz@192.168.1.110:.
輸出
scp 在不壓縮的情況下傳輸文件
Executing:?program?/usr/bin/ssh?host?202.x.x.x,?user?mrarianto,?command?scp?-v?-p?-t?.
OpenSSH_6.0p1?Debian-3,?OpenSSL?1.0.1c?10?May?2012
debug1:?Reading?configuration?data?/etc/ssh/ssh_config
debug1:?/etc/ssh/ssh_config?line?19:?Applying?options?for?*
debug1:?Connecting?to?202.x.x.x?[202.x.x.x]?port?22.
debug1:?Connection?established.
debug1:?identity?file?/home/pungki/.ssh/id_rsa?type?-1
debug1:?Found?key?in?/home/pungki/.ssh/known_hosts:1
debug1:?ssh_rsa_verify:?signature?correct
debug1:?Trying?private?key:?/home/pungki/.ssh/id_rsa
debug1:?Next?authentication?method:?password
rumenz@202.x.x.x's?password:
debug1:?Authentication?succeeded?(password).
Authenticated?to?202.x.x.x?([202.x.x.x]:22).
debug1:?Sending?command:?scp?-v?-p?-t?.
File?mtime?1323853868?atime?1380425711
Sending?file?timestamps:?T1323853868?0?1380425711?0
messages.log?100%?93MB?58.6KB/s?27:05
Transferred:?sent?97614832,?received?25976?bytes,?in?1661.3?seconds
Bytes?per?second:?sent?58758.4,?received?15.6
debug1:?Exit?status?0
-C
?允許壓縮
rumenz@local?$?scp?-Cpv?messages.log?rumenz@192.168.1.110:.
輸出
scp 使用壓縮更快地傳輸文件
Executing:?program?/usr/bin/ssh?host?202.x.x.x,?user?mrarianto,?command?scp?-v?-p?-t?.
OpenSSH_6.0p1?Debian-3,?OpenSSL?1.0.1c?10?May?2012
debug1:?Reading?configuration?data?/etc/ssh/ssh_config
debug1:?/etc/ssh/ssh_config?line?19:?Applying?options?for?*
debug1:?Connecting?to?202.x.x.x?[202.x.x.x]?port?22.
debug1:?Connection?established.
debug1:?identity?file?/home/pungki/.ssh/id_rsa?type?-1
debug1:?Host?'202.x.x.x'?is?known?and?matches?the?RSA?host?key.
debug1:?Found?key?in?/home/pungki/.ssh/known_hosts:1
debug1:?ssh_rsa_verify:?signature?correct
debug1:?Next?authentication?method:?publickey
debug1:?Trying?private?key:?/home/pungki/.ssh/id_rsa
debug1:?Next?authentication?method:?password
rumenz@202.x.x.x's?password:
debug1:?Enabling?compression?at?level?6.
debug1:?Authentication?succeeded?(password).
Authenticated?to?202.x.x.x?([202.x.x.x]:22).
debug1:?channel?0:?new?[client-session]
debug1:?Sending?command:?scp?-v?-p?-t?.
File?mtime?1323853868?atime?1380428748
Sending?file?timestamps:?T1323853868?0?1380428748?0
Sink:?T1323853868?0?1380428748?0
Sending?file?modes:?C0600?97517300?messages.log
messages.log?100%?93MB?602.7KB/s?02:38
Transferred:?sent?8905840,?received?15768?bytes,?in?162.5?seconds
Bytes?per?second:?sent?54813.9,?received?97.0
debug1:?Exit?status?0
debug1:?compress?outgoing:?raw?data?97571111,?compressed?8806191,?factor?0.09
debug1:?compress?incoming:?raw?data?7885,?compressed?3821,?factor?0.48
如果你要通過(guò)網(wǎng)絡(luò)復(fù)制大量文件,
-C
?參數(shù)將幫助你減少所需的總時(shí)間。
壓縮方法不適用于所有文件。當(dāng)源文件已經(jīng)被壓縮時(shí),就沒(méi)有什么效果了。文件如
.zip
,.rar
,pictures
, 和.iso
更改 scp 密碼以加密文件
默認(rèn)情況下
scp
使用?AES-128
?來(lái)加密文件。如果你想更改為其他密碼對(duì)其進(jìn)行加密,你可以使用?-c
?范圍??纯催@個(gè)命令。
rumenz@local?$?scp?-c?3des?Label.pdf?rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?282.5KB/s?00:13
上面的命令告訴
scp
使用3des algorithm
來(lái)加密文件。請(qǐng)注意此參數(shù)使用?-c
不是-C
。
使用 scp 命令限制帶寬使用
另一個(gè)可能有用的參數(shù)是?
-l
?范圍。這?-l
?參數(shù)將限制使用的帶寬制 。如果你執(zhí)行自動(dòng)化腳本來(lái)復(fù)制大量文件,這將很有用
rumenz@local?$?scp?-l?400?Label.pdf?rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?50.3KB/s?01:13
scp 默認(rèn)帶寬的單位是
Kilobyte/sec
(KB/s
)。所以如果你想限制你的帶寬scp
最多只有50 KB/s
,你需要將其設(shè)置為50 x 8
=400
.
指定要與 scp 一起使用的特定端口
scp
正在使用端口22
作為默認(rèn)端口。但出于安全原因,你可以將端口更改為另一個(gè)端口. 例如,我們使用端口2249
.
rumenz@local?$?scp?-P?2249?Label.pdf?rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?262.3KB/s?00:14
遞歸復(fù)制目錄中的文件
有時(shí)我們需要復(fù)制目錄和其中的所有
文件
,目錄
。
rumenz@local?$?scp?-r?documents?rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?282.5KB/s?00:13
scp.txt?100%?10KB?9.8KB/s?00:00
復(fù)> 制過(guò)程完成后,你將在目標(biāo)服務(wù)器上找到一個(gè)名為documents
及其所有文件。文件夾documents
是自動(dòng)創(chuàng)建的。
禁用進(jìn)度表和警告 / 診斷消息
rumenz@local?$?scp?-q?Label.pdf?rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
rumenz@local?$
可以看到,輸入密碼后,沒(méi)有關(guān)于 scp 進(jìn)程的信息。該過(guò)程完成后,你將再次看到提示。
通過(guò)代理使用 scp 復(fù)制文件
代理服務(wù)器通常用于辦公環(huán)境。scp 本身沒(méi)有配置代理。當(dāng)你的環(huán)境使用代理時(shí),你必須告訴scp 與代理進(jìn)行通信。
例如代理地址是
10.0.96.6
代理端口是8080
.代理還實(shí)現(xiàn)了用戶身份驗(yàn)證。首先,你需要?jiǎng)?chuàng)建?~/.ssh/config
文件
ProxyCommand?/usr/bin/corkscrew?10.0.96.6?8080?%h?%p?~/.ssh/proxyauth
然后你需要?jiǎng)?chuàng)建文件?
~/.ssh/proxyauth
?里面輸入。
myusername:mypassword
前提是需要安裝
corkscrew
$?apt-get?install?corkscrew
Centos系統(tǒng)可以用
yum
安裝corkscrew
#?yum?install?corkscrew
由于?
~/.ssh/proxyauth
?文件包含你的?username
和password
?以明文格式,請(qǐng)確保該文件只能自己訪問(wèn)。
選擇不同的ssh_config 文件
對(duì)于經(jīng)常在公司網(wǎng)絡(luò)和公共網(wǎng)絡(luò)之間切換的移動(dòng)用戶來(lái)說(shuō),總是在scp中更改設(shè)置會(huì)很痛苦。
場(chǎng)景示例
代理在公司網(wǎng)絡(luò)中使用,但不在公共網(wǎng)絡(luò)中使用,并且你定期切換網(wǎng)絡(luò)。
rumenz@local?$?scp?-F?/home/pungki/proxy_ssh_config?Label.pdf
rumenz@192.168.1.110:.
rumenz@202.x.x.x's?password:
Label.pdf?100%?3672KB?282.5KB/s?00:13
默認(rèn)情況下?
ssh_config
?每個(gè)用戶的文件將被放置在?~/.ssh/config
。創(chuàng)建一個(gè)特定的?ssh_config
?具有代理兼容性的文件將更容易在網(wǎng)絡(luò)之間切換。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-546009.html
當(dāng)你在公司網(wǎng)絡(luò),你可以使用?
-F
?范圍。當(dāng)你在公共網(wǎng)絡(luò)上時(shí),你可以不用-F
參數(shù)。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-546009.html
到了這里,關(guān)于在Linux中傳輸文件文件夾的10個(gè)scp命令的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!