Vagrant的Ubuntu 16.04 vagrantfile默认密码

Vagrant's Ubuntu 16.04 vagrantfile default password

我正在尝试通过 Vagrant 1.9.1 部署 运行 Ubuntu 16.04 虚拟机。 我使用的 Vagrantfile 来自 Atlas:

Ubuntu Xenial 16.04 Vagrantfile

我正在使用 Debian Stretch 作为主机 OS。 Vagrant 是通过 Vagrant 网站上提供的 .deb 安装的。

Vagrantfile 运行 并正确部署。我可以通过我的主机 OS 和使用 'vagrant ssh' ssh 进入虚拟机。但是,我在尝试从外部通过 ssh 进入时遇到了一个小障碍。

此 VM 中的默认用户名为 'ubuntu',并且似乎设置了密码。但是,我根本不知道密码是什么,而且似乎没有文档包含我要查找的信息。尝试通过 'passwd' 在 VM 中设置密码会要求提供当前密码。有人知道这是怎么回事吗?

所以我的大问题是:有没有其他人部署了同样的 Vagrantfile,如果有,有人知道默认用户的密码是什么吗?

在撰写此答案时:没有人曾在 ubuntu/xenial64 Vagrant box 上公开分享用户 ubuntu 的密码(参见 #1569237)。

没必要。您可以:

  • 使用 SSH 密钥身份验证登录
  • 使用 sudo passwd ubuntu 更改密码(默认情况下 ubuntu 用户具有设置 NOPASSWD 的 sudo 权限)

实际上,不仅可以,而且您应该更改密码。

正如用户@prometee 在此启动板讨论中提到的那样,密码位于 ~/.vagrant.d/ubuntu-VAGRANTSLASH-xenial64/20161221.0.0/virtualbox/Vagrantfile #1569237

这是我的(第 8 行):

# 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 = "022999D56C03"
  config.ssh.username = "ubuntu"
  config.ssh.password = "fbcd1ed4fe8c83b157dc6e0f"

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

仅供参考,用户@racb 在同一个讨论中提到 this bug report having been filed to ubuntu 到目前为止 no [...] decision has been made yet 关于它。

新的 ubuntu/xenial64 图像没有默认的用户名和密码。但是,您可以使用在您的 vagrant 文件夹中生成的 ssh 密钥进行 ssh。

假设您的 Vagrantfile 位于 /vagrant/vm01/Vagrantfile,ssh 密钥将位于 /vagrant/vm01/.vagrant/machines/..../private_key

您可以使用此 private_key 登录您的 vagrant 虚拟机。如果来宾机器要求输入密钥的密码,只需点击 ENTER(指定一个空白密码)。例如,在我的 Mac:

ssh -i /vagrant/vm01/.vagrant/..../private_key <your vm user>@<your vm ip>:<your vm port>

如果您仍然想使用用户名和密码登录,使用private_key登录后,您可以添加自己的用户以便稍后登录:

# create a user for log in
sudo useradd yourusername

# specify a password
sudo passwd yourusername
# then type your password when prompted

# add the user to sudo group
sudo adduser yourusername sudo    

# create a home folder for your user
sudo mkdir /home/yourusername

# add a shell command for your user (normally /bin/bash)
sudo vim /etc/passwd
# find yourusername line, and add /bin/bash to the end.
# the end result would look like this:
yourusername:x:1020:1021::/home/yourusername:/bin/bash

现在您可以使用新的用户名和密码进行 ssh。

如果这可以帮助:

我通过创建普通 VM(在我的例子中是 ubuntu/xenial)解决了自定义打包问题,然后复制在 vagrant ssh-config 中找到的识别文件并将该文件用于 config.sshprivate_key_path,另外还要将 config.ssh.username 设置为 ubuntu。 (另见 https://github.com/hashicorp/vagrant/issues/5186#issuecomment-355012068

不确定通过 vagrant 安装时的 ubuntu 16.X 密码,但您可以按照以下步骤自行更改密码 -

[~/from-vagrant-project]vagrant ssh
[ubuntu@hostname]sudo -i
root@hostname:~# passwd ubuntu
Enter new UNIX password:XXXXX
Retype new UNIX password:XXXXX
passwd: password updated successfully`

默认用户和密码是:

用户:流浪汉 密码:流浪汉