scp是有Security的文件copy,基于ssh登录。操作起来比较方便,比如要把当前一个文件copy到远程另外一台主机上
从 本地 复制到 远程(都是Linux系统时)
命令格式:
scp -r local_file remote_username@remote_ip:remote_folder
或者
scp -r local_file remote_username@hostname:remote_folder (这里使用hostname,是因为提前配置了hosts映射)
或者
scp -r local_file remote_username@remote_ip:remote_file
或者
scp -r local_file remote_ip:remote_folder
或者
scp -r local_file remote_ip:remote_file
注:-r 是递归的意思,相当于把文件目录包括里面的内容都递归复制到目标机器
如果没有配置ssh无密登录会在输入复制命令回车后要去输入远程机器的用户登录密码
从远程机器复制到本地当前操作的机器(跟上面操作反过来)remote_ip同样可以换成hostname,条件也是提前配置了hosts映射
如:scp -r remote_username@remote_ip:remote_file ./
注:./的意思是当前所在目录,即正在操作的当前机器目录位置,也可以写成具体路径:
scp -r remote_username@remote_ip:remote_file local_username@hostname:local_folder
这里的local_username和local_folder是指正在操作的机器,可能是实体物理机,也可能是虚拟机,也可能是远程机器(正在输入要执行命令的机器)
从本机操作远程机器,将远程机器文件复制到另一台远程机器(三台机器)
scp -r remote_username1@remote_ip1:remote_file1 username2@remote_ip2:remote_file2
注:
remote_file1需要复制的文件既可以是文本也可以是目录,而remote_file2是用来存放remote_file1的目录(位置)
remote_ip可以换做hostname,前提是远程机器上做了hosts映射,把它自己的ip映射为自己的hostname
如:scp -r atguigu@hadoop103:/opt/software/demo.txt atguigu@hadoop104:/opt/software(如果没有配置ssh无秘登录,会依次要求输入主机hadoop103和主机hadoop104的用户密码的)
从 远程 复制到 本地,只要将 从 本地 复制到 远程 的命令 的 后2个参数 调换顺序 即可;