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

相关文章
相关标签/搜索