簡單介紹
scp
的全稱是:Secure Copy Protocol
(安全復制協議),是Linux
中用于在網絡中安全傳輸文件的命令行工具。它基于SSH
協議,用于在本地服務器和遠程服務器之間,或者兩臺遠程服務器之間復制文件或目錄。
scp
基本語法格式如下:
scp [選項] 源路徑 目標路徑
常用選項說明:
-r
:遞歸復制整個目錄。-P
:指定非默認的SSH
端口號,默認為22
。這里注意為大寫的P
。-C
:啟用壓縮,提高傳輸效率。這里注意為大寫的C
。-i
:指定身份驗證文件(私鑰文件)。
以下是幾種常見的scp
命令使用示例,可以直接套用。指定本地路徑時,可以使用相對路徑。
1. 從本地復制文件到遠程
scp /path/to/local/file user@remote_host:/path/to/remote/destination
2. 從遠程復制文件到本地
scp user@remote_host:/path/to/remote/file /path/to/local/destination
3. 從本地復制目錄到遠程
scp -r /path/to/local/directory user@remote_host:/path/to/remote/destination
4. 從遠程復制目錄到本地
scp -r user@remote_host:/path/to/remote/directory /path/to/local/destination
5. 從一臺遠程服務器復制文件到另一臺遠程服務器
scp user1@host1:/path/to/file user2@host2:/path/to/destination
6. 從一臺遠程服務器復制目錄到另一臺遠程服務器
scp -r user1@host1:/path/to/directory user2@host2:/path/to/destination
在復制過程中,可能需要輸入遠程服務器指定用戶的密碼。
the end.