无法使用 Vagrant 将文件 scp 到 Ubuntu 14

无法使用 Vagrant 将文件 scp 到 Ubuntu 14

我正在尝试将文件从我的机器桌面复制到我的 vagrant box 中,但我似乎一直遇到这个错误。

ssh: connect to host 127.0.0.1 port 22: Connection refused
lost connection

我查看了我的 vagrant 文件并发现了以下行:

 Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
 config.vm.network "forwarded_port", guest: 80, host: 8080

我尝试运行这些命令并分别收到以下错误:

scp -P 80 nginx.conf [email protected]:/etc/nginx/nginx.conf
ssh: connect to host 127.0.0.1 port 80: Connection refused
lost connection

scp -P 8080 nginx.conf [email protected]:/etc/nginx/nginx.conf
ssh_exchange_identification: Connection closed by remote host
lost connection

我尝试运行这些命令,但它仍然不起作用。

sudo apt-get install openssh-client
sudo apt-get install openssh-server

任何帮助,将不胜感激。

答案1

根据Vagrant 文档,通过 SSH 进入 Vagrant box 的正确方法是:

vagrant ssh

查看配置设置流浪者SSH了解如何管理 SSH。此外,还可以查看https://stackoverflow.com/questions/16704059/easiest-way-to-copy-a-single-file-from-host-to-vagrant-guest了解将文件复制到 Vagrant 机器的一些方法。

答案2

您向我们展示的这些行很可能用于 http 访问(使用您的网络浏览器)。

要找到您必须使用 ssh/scp 的端口,请在键入后按照启动过程进行操作vagrant up,您将找到有关转发端口 22->2200(或类似端口)的行。

然后,您必须指定“vagrant”作为连接该框的用户。对于普通的 ssh 访问,标准vagrant ssh更简单。

相关内容