ssh - Vagrant up 一直要求输入密码

标签 ssh vagrant vagrantfile

起初我收到这个错误:

Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.

vagrant@127.0.0.1's password:



然后我安装了:高线

现在我只得到:

vagrant@127.0.0.1's password:



我试过用vagrant有密码。

我没工作。我试过我的电脑密码,它也不起作用。

所以我不知道我应该使用什么密码。

所有这一切都是在我添加这些设置之后开始的(在 Vagrantfile 中):
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.ssh.keys_only = true
config.ssh.insert_key = true

有人可能会问我为什么要使用这些设置(因为通常 vagrant 是默认的用户名和密码)。原因是由于某种原因,该框会生成一些随 secret 码并使用具有用户名的 ubuntu。
# Front load the includes
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)

Vagrant.configure("2") do |config|
  config.vm.base_mac = "02357F2D68C4"
  config.ssh.username = "ubuntu"
  config.ssh.password = "1547c59e6cbdffd4104ad720"

  config.vm.provider "virtualbox" do |vb|
     vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
     vb.customize [ "modifyvm", :id, "--uartmode1", "file", File.join(Dir.pwd, "ubuntu-zesty-17.04-cloudimg-console.log") ]
  end
end

这是在以下位置找到的:~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-zesty64/20170412.1.0/virtualbox
我尝试了这个解决方案,但没有奏效:

vagrant asks password at only the first time 'vagrant up'

那么密码是什么呢?
我该怎么做才能让它停止询问密码?

Vagrant 1.9.1

本地操作系统:

No LSB modules are available.

Distributor ID: Ubuntu

Description: Ubuntu 17.04

Release: 17.04

Codename: zesty



盒子:ubuntu/zesty64(虚拟盒子,20170412.1.0)

更新 1
$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/zesty64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'ubuntu/zesty64'
    default: URL: https://atlas.hashicorp.com/ubuntu/zesty64
==> default: Adding box 'ubuntu/zesty64' (v20170412.1.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/ubuntu/boxes/zesty64/versions/20170412.1.0/providers/virtualbox.box
==> default: Successfully added box 'ubuntu/zesty64' (v20170412.1.0) for 'virtualbox'!
==> default: Importing base box 'ubuntu/zesty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/zesty64' is up to date...
==> default: Setting the name of the VM: -----
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 3306 (guest) => 3306 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: password
    default: Warning: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
vagrant@127.0.0.1's password: 
vagrant@127.0.0.1's password: 
    default: Warning: Authentication failure. Retrying...
vagrant@127.0.0.1's password: ==> default: Waiting for cleanup before exiting...
Vagrant exited after cleanup due to external interrupt.

最佳答案

我想你有些困惑。
config.ssh.username将引用用于登录的用户,但 此用户必须存在 在虚拟机中,你不能决定使用自己的名字,它会起作用;如果虚拟机中没有相应的用户,它将无法工作。

Vagrant 建议使用基于 key 的身份验证而不是密码,但是当您创建您的盒子时(通常使用 packer.io),您可以决定使用密码身份验证方法。

在 ubuntu/zesty64 box 的情况下,这就是所有者决定做的事情,它只创建了 ubuntu 用户并决定使用密码进行身份验证。

如果您更喜欢使用 vagrant 登录虚拟机,您首先需要创建 vagrant用户,您也可以下载public key .进行这些更改后,您可以重新包装盒子,以便将来再次使用时,所有设置都将保留。
您还可以使用 packer 构建自己的盒子,github 上有大量可用模板可以重复使用。

关于ssh - Vagrant up 一直要求输入密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45471187/

相关文章:

amazon-web-services - 带密码的 AWS ssh key 对

php - 带有 vagrant 数据库迁移的 Laravel 4 "using password NO"重置

ruby - Chef Recipe : Upstart daemon not starting with Ruby

php - 将 Laravel Homestead 用于 PHP5.6 和 PHP7 项目

virtual-machine - 将一些 Vagrant 盒子移动到外部驱动器

Vagrant VirtualBox 名称保留为默认值

git - 将 SSH 用户限制为 shell 命令

visual-studio - Visual Studio Code 远程开发使 AWS 实例崩溃

vagrant - 带有插件的自定义 Vagrant 命令

encryption - 无法为新用户生成有效的 ssh 公钥/私钥对