如何將 ssh-copy-id 從主機作業系統複製到 vagrant 來賓作業系統

如何將 ssh-copy-id 從主機作業系統複製到 vagrant 來賓作業系統

我創建了一台流浪的訪客機器。下面是Vagrantfile——

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/lunar64"

  config.vm.network "private_network", ip: "192.168.33.10"

   config.vm.provider "virtualbox" do |vb|
     vb.memory = "1024"
   end
end

當我對來賓電腦執行 ping 操作時,它在主機上工作正常。

$ ping -c 3 192.168.33.10
PING 192.168.33.10 (192.168.33.10) 56(84) bytes of data.
64 bytes from 192.168.33.10: icmp_seq=1 ttl=64 time=0.606 ms
64 bytes from 192.168.33.10: icmp_seq=2 ttl=64 time=0.588 ms
64 bytes from 192.168.33.10: icmp_seq=3 ttl=64 time=0.301 ms

--- 192.168.33.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2031ms
rtt min/avg/max/mdev = 0.301/0.498/0.606/0.139 ms

現在我想ssh-copy-id從主機進入客戶作業系統。我知道我可以使用 command ssh 進入 vagrant vagrant ssh。但我想使用來賓作業系統的 IP 位址進行 ssh,例如ssh 192.168.33.10.

但我遇到了以下錯誤 -

$ ssh-copy-id 192.168.33.10
The authenticity of host '192.168.33.10 (192.168.33.10)' can't be established.
ED25519 key fingerprint is SHA256:Ultxy8OXuoD+ftDsJvy19fYbJNBS/znIukm+39GNdLE.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 2 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]: Permission denied (publickey).

我想這樣做,因為我正在使用 vagrant 學習 ansible 劇本。我該如何解決這個問題?

相關內容