linux下scp命令詳解

來源:互聯網
上載者:User

scp是 secure copy的縮寫, scp是linux系統下基於ssh登陸進行安全的遠程檔案拷貝命令。linux的scp命令可以在linux伺服器之間複製檔案和目錄.

scp命令的用處:

      scp在網路上不同的主機之間複製檔案,它使用ssh安全性通訊協定傳輸資料,具有和ssh一樣的驗證機制,從而安全的遠程拷貝檔案。

scp命令基本格式:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]

[-l limit] [-o ssh_option] [-P port] [-S program]

[[user@]host1:]file1 [...] [[user@]host2:]file2

scp命令的參數說明:

-1

強制scp命令使用協議ssh1

-2

強制scp命令使用協議ssh2

-4

強制scp命令只使用IPv4定址

-6

強制scp命令只使用IPv6定址

-B

使用批處理模式(傳輸過程中不詢問傳輸口令或短語)

-C

允許壓縮。(將-C標誌傳遞給ssh,從而開啟壓縮功能)

-p 保留原檔案的修改時間,訪問時間和存取權限。

-q

不顯示傳輸進度條。

-r

遞迴複製整個目錄。

-v 詳細方式顯示輸出。scp和ssh(1)會顯示出整個過程的調試資訊。這些資訊用於調試串連,驗證和配置問題。

-c cipher

以cipher將資料轉送進行加密,這個選項將直接傳遞給ssh。

-F ssh_config

指定一個替代的ssh設定檔,此參數直接傳遞給ssh。

-i identity_file

從指定檔案中讀取傳輸時使用的密鑰檔案,此參數直接傳遞給ssh。

-l limit

限定使用者所能使用的頻寬,以Kbit/s為單位。

-o ssh_option

如果習慣於使用ssh_config(5)中的參數傳遞方式,

-P port 注意是大寫的P, port是指定資料轉送用到的連接埠號碼

-S program

指定加密傳輸時所使用的程式。此程式必須能夠理解ssh(1)的選項。

scp命令的實際應用

1>從本機伺服器複製到遠程伺服器

(1) 複製檔案:

命令格式:

scp local_file remote_username@remote_ip:remote_folder

或者

scp local_file remote_username@remote_ip:remote_file

或者

scp local_file remote_ip:remote_folder

或者

scp local_file remote_ip:remote_file

第1,2個指定了使用者名稱,命令執行後需要輸入使用者密碼,第1個僅指定了遠端目錄,檔案名稱字不變,第2個指定了檔案名稱

第3,4個沒有指定使用者名稱,命令執行後需要輸入使用者名稱和密碼,第3個僅指定了遠端目錄,檔案名稱字不變,第4個指定了檔案名稱

執行個體:

scp /home/linux/soft/scp.zip root@www.mydomain.com:/home/linux/others/soft

scp /home/linux/soft/scp.zip root@www.mydomain.com:/home/linux/others/soft/scp2.zip

scp /home/linux/soft/scp.zip www.mydomain.com:/home/linux/others/soft

scp /home/linux/soft/scp.zip www.mydomain.com:/home/linux/others/soft/scp2.zip

(2) 複製目錄:

命令格式:

scp -r local_folder remote_username@remote_ip:remote_folder

或者

scp -r local_folder remote_ip:remote_folder

第1個指定了使用者名稱,命令執行後需要輸入使用者密碼;

第2個沒有指定使用者名稱,命令執行後需要輸入使用者名稱和密碼;

例子:

scp -r /home/linux/soft/ root@www.mydomain.com:/home/linux/others/

scp -r /home/linux/soft/ www.mydomain.com:/home/linux/others/

上面 命令 將 本地 soft 目錄 複製 到 遠程 others 目錄下,即複製後遠程伺服器上會有/home/linux/others/soft/ 目錄

2>從遠程伺服器複製到本機伺服器

從遠程複製到本地的scp命令與上面的命令雷同,只要將從本地複製到遠端命令後面2個參數互換順序就行了。

例如:

scp root@www.mydomain.com:/home/linux/soft/scp.zip /home/linux/others/scp.zip

scp www.mydomain.com:/home/linux/soft/ -r /home/linux/others/

linux系統下scp命令中很多參數都和 ssh1 有關 , 還需要看到更原汁原味的參數資訊,可以運行man scp 看到更細緻的英文說明.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.