首页 文章

Vagrant的Ubuntu 16.04 vagrantfile默认密码

提问于
浏览
19

我正在尝试通过Vagrant 1.9.1部署和运行Ubuntu 16.04 VM . 我正在使用的Vagrantfile来自Atlas:

Ubuntu Xenial 16.04 Vagrantfile

我正在使用Debian Stretch作为主机操作系统 . Vagrant是通过Vagrant网站上的.deb安装的 .

Vagrantfile可以正确运行和部署 . 我可以通过我的主机操作系统和使用'vagrant ssh'进入虚拟机 . 但是,当我尝试从外面进入ssh时,我有一个小阻滞剂 .

此VM中的默认用户名为“ubuntu”,并且设置了密码 . 但是,我根本不知道密码是什么,没有文档似乎有我正在寻找的信息 . 尝试通过VM中的“passwd”设置密码要求输入当前密码 . 有谁知道这是怎么回事?

所以我的一个大问题是:有没有其他人部署过同样的Vagrant文件,如果是这样,有人知道默认用户的密码是什么吗?

5 回答

  • 23

    在写这个答案时:没有人在ubuntu / xenial64 Vagrant盒子上公开分享用户ubuntu的密码(参见#1569237) .

    这不是必需的 . 您可以:

    • 使用SSH密钥身份验证登录

    • 使用 sudo passwd ubuntu 更改密码(默认 ubuntu 用户具有设置为 NOPASSWD 的sudo权限)

    实际上,不仅你可以,而且你 should 更改密码 .

  • 0

    密码位于 ~/.vagrant.d/ubuntu-VAGRANTSLASH-xenial64/20161221.0.0/virtualbox/Vagrantfile 中,用户@prometee在此启动板讨论#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 .

  • 27

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

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

    您可以使用 private_key 登录您的vagrant vm . 如果客户机要求输入密钥的密码,只需按 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了 .

  • -1

    通过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`
    
  • 3

    如果这可以帮助:

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

相关问题