用scp将主机中的文件复制到虚拟机中的客户机中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用scp将主机中的文件复制到虚拟机中的客户机中相关的知识,希望对你有一定的参考价值。
主机操作系统是ubuntu, 虚拟机中的操作系统也是ubuntu, 如何运用scp命令, 将主机中的文件或文件夹复制到虚拟机的操作系统中. 注意, 只能过scp, 不依靠其他软件, 主机与客户机的ip地址都已知.
我可以在客户机中用scp命令将客户机中的文件复制到虚拟机外的主机中, 但是却无法从主机复制文件到客户机中. 主机的ip是202.201.13.87, 客户机的ip为10.0.2.15. 各位朋友们, 从虚拟机的ip地址可以看出它用的私有地址, 私有地址可以重复使用, 因此除了这台虚拟机外, 网络中还有某台机子的ip地址也是10.0.2.15, 这时候问题来了, 当虚拟机外的主机ping 10.0.2.15时, 它怎么知道这个ip地址是虚拟机中的客户机所有, 还中网络中另外一台机子所有?
例如拷贝文件test.txt 到客户机/tmp下,客户机IP:192.168.0.2
scp test.txt root@192.168.0.2:/tmp
拷贝test目录到客户机/tmp下:
scp -r test root@192.168.0.2:/tmp
前提是主机能够ssh到客户机追问
换个简单点的说法, 虚拟机中客户机可以ping通虚拟机外的主机, 但是主机ping不通客户机, 这是导致scp不成功的根本原因, 请问这该怎么解决.
追答检查客户机防火墙设置
主机上执行:traceroute -d 10.0.2.15 查看卡在什么地方
ping到哪个10.0.2.15,是由路由器设置的
私有地址相同,如果两台机器的ip还能存在,那说明两个ip的网关不一样,不然就是ip冲突,有一台电脑的ip是无效的。 参考技术B 假设两个主机的ip是192.168.1.1和192.168.1.2
scp usr1@192.168.1.1 :filename1 usr2@192.168.1.2:filename2
输入对应的用户密码就可以完成cp
“我可以在客户机中用scp命令将客户机中的文件复制到虚拟机外的主机中, 但是却无法从主机复制文件到客户机中. 主机的ip是202.201.13.87, 客户机的ip为10.0.2.15”
说明你在客户机上没有运行 sshd服务。追问
我在主机中连ping都ping不通客户机, 应该不是ssh的问题.
参考技术C 你主机无法ping通客户机应该是你搭建虚拟机的时候桥接关系选择不对,换个桥接关系试试利用docker制作一个带有redis软件的镜像,供其他人使用
1. 宿主机在etc/apt/下创建一个haha的文件夹
2.宿主机将haha文件夹映射到容器的虚拟系统中etc/apt/
3. 此时,可以在宿主机和容器虚拟机中同步创建和删除文件
4. 将宿主机中的source.list文件同步到容器浏览器中。
4.1 更新前容器虚拟机中的更新源
4.2 同步替换后的更新源
4.2.1 宿主机将sources.list拷贝到同步文件夹
4.2.2 容器虚拟机从同步文件夹中将sources.list拷贝到对应位置,覆盖掉原来的sources.list
4.2.3 容器虚拟机更新源
apt-get update
报错:Is the package apt-transport-https installed?
安装:apt-get install apt-transport-https 依然报同样的错
报错:Unable to locate package apt-transport-https
原因:sources.list 问题,换成清华园的sources.list即可,直接更新。
![技术图片](/img/jia.gif)
1 # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted 2 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted #Added by software-properties 3 4 # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 5 # newer versions of the distribution. 6 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted 7 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse universe #Added by software-properties 8 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted 9 10 ## Major bug fix updates produced after the final release of the 11 ## distribution. 12 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted 13 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse restricted universe main #Added by software-properties 14 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted 15 16 ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 17 ## team, and may not be under a free licence. Please satisfy yourself as to 18 ## your rights to use the software. Also, please note that software in 19 ## universe WILL NOT receive any review or updates from the Ubuntu security 20 ## team. 21 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe 22 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial universe 23 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe 24 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe 25 26 ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 27 ## team, and may not be under a free licence. Please satisfy yourself as to 28 ## your rights to use the software. Also, please note that software in 29 ## multiverse WILL NOT receive any review or updates from the Ubuntu 30 ## security team. 31 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse 32 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse 33 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse 34 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse 35 36 ## N.B. software from this repository may not have been tested as 37 ## extensively as that contained in the main release, although it includes 38 ## newer versions of some applications which may provide useful features. 39 ## Also, please note that software in backports WILL NOT receive any review 40 ## or updates from the Ubuntu security team. 41 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse 42 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties 43 # deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse 44 45 ## Uncomment the following two lines to add software from Canonical‘s 46 ## ‘partner‘ repository. 47 ## This software is not part of Ubuntu, but is offered by Canonical and the 48 ## respective vendors as a service to Ubuntu users. 49 # deb http://archive.canonical.com/ubuntu xenial partner 50 # deb-src http://archive.canonical.com/ubuntu xenial partner 51 52 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted 53 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse restricted universe main #Added by software-properties 54 # deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted 55 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe 56 # deb-src http://security.ubuntu.com/ubuntu xenial-security universe 57 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse 58 # deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse
apt-get update
以上是关于用scp将主机中的文件复制到虚拟机中的客户机中的主要内容,如果未能解决你的问题,请参考以下文章