Linux scp 命令用於 Linux 之間復制文件和目錄。
scp 是 secure copy 的縮寫, scp 是 linux 系統下基於 ssh 登陸進行安全的遠程文件拷貝命令。
scp 是加密的,rcp 是不加密的,scp 是 rcp 的加強版。肯定建議加密好一些
常用方法介紹:
本地文件復制到遠程主機: scp local_file user@host:/dir scp -P 16022 local_file user@host:/dir #ssh的端口不是默認的端口要指定! 遠程文件復制到本機: scp user@host:/dir local_file 如果是目錄,需要加上-r 參數
說明:
-a 盡可能將檔案狀態、權限等資料都照原狀予以復制 -r 若 source 中含有目錄名,則將目錄下之檔案亦皆依序拷貝至目的地 -f 若目的地已經有相同檔名的檔案存在,則在復制前先予以刪除再行復制 -v 和大多數 linux 命令中的 -v 意思一樣 , 用來顯示進度 . 可以用來查看連接 , 認證 , 或是配置錯誤 -C 使能壓縮選項 -P 選擇端口 . 注意 -p 已經被 rcp 使用 -4 強行使用 IPV4 地址 -6 強行使用 IPV6 地址
復制
[root@ansz.quan.bbs ~]$touch ab [root@ansz.quan.bbs ~]$scp -P 20042 ab apps@192.168.111.153:/tmp The authenticity of host '[192.168.111.153]:20042 ([192.168.111.153]:20042)' can't be established. RSA key fingerprint is 3c:ff:51:9e:3c:cc:dd:66:42:f1:49:09:4f:5c:a0:96. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[192.168.111.153]:20042' (RSA) to the list of known hosts. apps@192.168.111.153's password: ab 100% 0 0.0KB/s 00:00
檢測:
[root@mysql.bktwo.quan.bbs ~]$cd /tmp/ [root@mysql.bktwo.quan.bbs tmp]$ls 90-nproc.conf.20200207 limits.conf.20200207 yum_save_tx-2020-02-18-09-20YQ6Wj3.yumtx ab sysctl.conf.20200207 Initialize.quan.sh yum.log
注意:客戶端和服務端都是要安裝scp命令包的yum install openssh-clients
否則出現下面的情況:
[root@ansz.quan.bbs ~]$scp -P 20042 ab apps@192.168.111.152:/tmp The authenticity of host '[192.168.111.152]:20042 ([192.168.111.152]:20042)' can't be established. RSA key fingerprint is 3c:ff:51:9e:3c:cc:dd:66:42:f1:49:09:4f:5c:a0:96. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[192.168.111.152]:20042' (RSA) to the list of known hosts. apps@192.168.111.152's password: bash: scp: command not found lost connection
