良许Linux教程网 干货合集 详解scp命令使用实例

详解scp命令使用实例

scp是secure copy的简写, 是 linux 系统下基于 ssh 登陆进行安全的远程文件拷贝命令。scp 是加密的,rcp 是不加密的,scp 是 rcp 的加强版,下面为大家详细讲解一下scp命令使用实例。

Linux scp命令

基本格式

scp source target

将本地文件复制到远端服务器上

[student@servera ~]scp log.tar root@serverb:/logbackup
The authenticity of host 'serverb (172.25.250.11)' can't be established.
ECDSA key fingerprint is SHA256:BCd8VCfEpGbUo3zb1De0hd1Q5nOMEzYNpMFu5o7j4Fg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'serverb,172.25.250.11' (ECDSA) to the list of known hosts.
root@serverb's password:
log.tar                                                  100%   11MB  20.8MB/s   00:00    
[student@servera ~] ssh root@serverb "ls /logbackup"
root@serverb's password:
log.tar
  • root@ 是可选项,如果不指定,则使用你当前的本地用户。你所使用的用户必须要对远端主机上的对应目录有相应的权限。
  • 和 ssh 一样,第一次连接的时候,会有一个安全性的提示,选项 yse 就可以了,因为 scp 就是 OpenSSH 的一部分。

从远端就复制文件到本地

[student@servera ~]scp root@serverb:/logbackup/log.tar backup/
root@serverb's password:
log.tar                                                  100%   11MB  25.5MB/s   00:00    
[student@servera ~] ls backup/
log.tar

如果是目录,我们可以通过 -r 选项进行递归的方式,复制整个目录内容

[student@servera ~]$ scp -r root@serverb:/var/log/ backup/
root@serverb's password:
lastlog                                                  100%  285KB   5.9MB/s   00:00    
README                                                   100% 1040   260.8KB/s   00:00    
wtmp                                                     100% 6912     2.6MB/s   00:00    
btmp                                                     100%    0     0.0KB/s   00:00    
audit.log                                                100%  208KB   8.0MB/s   00:00    
sssd.log                                                 100%    0     0.0KB/s   00:00    
sssd_implicit_files.log                                  100%  109    32.9KB/s   00:00    
sssd_nss.log                                             100%   94     8.6KB/s   00:00    
rhsm.log                                                 100% 3642     1.0MB/s   00:00    
tuned.log                                                100% 2434   904.9KB/s   00:00    
messages                                                 100% 1459KB  18.1MB/s   00:00    
secure                                                   100% 8298     3.4MB/s   00:00    
maillog                                                  100%    0     0.0KB/s   00:00    
spooler                                                  100%    0     0.0KB/s   00:00    
dnf.log                                                  100%  107KB   3.4MB/s   00:00    
dnf.librepo.log                                          100%  245KB   8.4MB/s   00:00    
dnf.rpm.log                                              100%   21KB   2.3MB/s   00:00    
hawkey.log                                               100%   18KB   3.8MB/s   00:00    
cron                                                     100% 7166   706.4KB/s   00:00    
boot.log                                                 100%    0     0.0KB/s   00:00    

我们还可以使用 scp 把一个文件从远端的一台主机,复制到另外一台主机上

[student@workstation ~]scp student@servera:/home/student/log.tar student@serverb:/home/student/
student@serverb's password:
log.tar                                                  100%  670KB  19.6MB/s   00:00    
Connection to servera closed.
[student@workstation ~] ssh student@serverb "ls -l"
total 672
-rw-rw-r--. 1 student student 686080 Nov  6 20:54 log.tar

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部