Linux scp經常使用命令

Linux scp命令用於Linux之間複製文件和目錄。linux

scp是 secure copy的縮寫, scp是linux系統下基於ssh登錄進行安全的遠程文件拷貝命令。安全

一、從本地複製到遠程

命令格式:服務器

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個指定了文件名。

複製目錄命令格式:ssh

scp -r local_folder remote_username@remote_ip:remote_folder 或者 scp -r local_folder remote_ip:remote_folder 
  • 第1個指定了用戶名,命令執行後須要再輸入密碼;
  • 第2個沒有指定用戶名,命令執行後須要輸入用戶名和密碼

二、從遠程複製到本地

從遠程複製到本地,只要將從本地複製到遠程的命令的後2個參數調換順序便可,以下實例spa

應用實例:ip

 scp remote_username@remote_ip:remote_folder local_file
 scp -r remote_ip:remote_folder local_file

說明

1.若是遠程服務器防火牆有爲scp命令設置了指定的端口,咱們須要使用 -P 參數來設置命令的端口號,命令格式以下:rem

#scp 命令使用端口號 4588
scp -p 4588 remote_username@remote_ip:remote_folder local_file 

2.使用scp命令要確保使用的用戶具備可讀取遠程服務器相應文件的權限,不然scp命令是沒法起做用的。it

相關文章
相關標籤/搜索