无法将文件从本地机器scp到vagrant

Dan*_*bio 2 ubuntu vagrant

我正在尝试将文件从我的机器桌面scp到我的流浪盒中,但我似乎一直在遇到这个错误.

ssh: connect to host 127.0.0.1 port 22: Connection refused
lost connection
Run Code Online (Sandbox Code Playgroud)

我查看了我的流浪文件并找到了这一行:

 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
Run Code Online (Sandbox Code Playgroud)

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

scp -P 80 nginx.conf xxxxx@127.0.0.1:/etc/nginx/nginx.conf
ssh: connect to host 127.0.0.1 port 80: Connection refused
lost connection

scp -P 8080 nginx.conf xxxxx@127.0.0.1:/etc/nginx/nginx.conf
ssh_exchange_identification: Connection closed by remote host
lost connection
Run Code Online (Sandbox Code Playgroud)

我试过运行这些命令,但它仍然无法正常工作.

sudo apt-get install openssh-client
sudo apt-get install openssh-server
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

我也在askubuntu.com上问了这个问题

Ako*_*rth 6

默认情况下,虚拟机上的ssh服务器可能会侦听端口22,该端口转发到主机上的端口2222.

所以你应该能够做到:

scp -P 2222 nginx.conf xxxxx@127.0.0.1:/etc/nginx/nginx.conf
Run Code Online (Sandbox Code Playgroud)

您可以使用找到的端口转发选项更改此设置,但是您需要相应地在guest虚拟机上设置ssh服务器(因此,如果ssh守护程序没有监听,则转发端口80不会做太多事情).

使客户端从外部可见的另一种方法是使用公共网络配置 - 这样它就可以从网络上的DHCP服务器获取IP地址(就像连接新的物理机一样),然后它可以通过这个地址访问.您可以在Vagrantfile中执行以下操作:

config.vm.network "public_network"
Run Code Online (Sandbox Code Playgroud)