LoginSignup
14
19

More than 5 years have passed since last update.

Vagrant box ubuntu/xenial64 の ubuntuユーザ の passwordについて

Last updated at Posted at 2017-05-04

背景

Ubuntu descktop が使いたいと思い、Vagrant の 公式box ubuntu/xenial64 を使用して環境を作っています。
Vagrantのconfig vb.gui = trueにし起動させ、いざ!ログイン!
と意気揚々とubuntu:ubuntuで試して見たら、ログインができない。
色々試してみても、ログインができない。
どういうこちゃ _(:3 」∠ )_
user: ubuntuのパスワードが全くわからないんですけど( ; ; )

ということがあり、ubuntuパスワードの発掘作業をしたことの備忘録になります。

結論

ubuntu ユーザのパスワードの表記場所

~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170501.0.0/virtualbox/Vagrantfile

の中に記載されている

config.ssh.username = "ubuntu"
config.ssh.password = "79eee261f17ac64e2481039d"

こいつの79eee261f17ac64e2481039dがパスワードになります。

注意)
パスワードは、PCなどによっても変わるようです。
ここに書いてあるpasswardを使ってもログインできないってなるので、ちゃんんと自分の.vagrant.d/ を確認してください。

Vagrantfile で passwordを上書きできないかの試み

Vagrantfileの設定を書き換えてみる

Vagrantfileのconfigに、config.ssh.password = 'ubuntu'を直接していすることで、パスワードを強制的にubuntuにできないか試してみます。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"

  config.ssh.username = 'ubuntu'
  config.ssh.password = 'ubuntu'

  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
  end
end

と、Vagrantfileを編集し、試してみました。

結果

はい。だめでした。

$ cat ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170501.0.0/virtualbox/Vagrantfile

# 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 = "02C9FD7CBFCE"
  config.ssh.username = "ubuntu"
  config.ssh.password = "79eee261f17ac64e2481039d"

  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

と、書き換わってません。
うーむ。これは、どうにかして、書き換えれるものなのだろうか???

~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-xenial64/20170501.0.0/virtualbox/Vagrantfile
config.ssh.passwordを直接書き換えてもだめでしたorz

感想

当面は、~/.vagrant.d/配下から、パスワードを漁る方法で良しとします。
ただ、デフォルトで作成されているubuntuユーザを使用するのではなく、Provisioningで、新規ユーザを作成した方が良いかもしれないと思いました。
この辺、いい方法ないだろうか。。。

追記

Provisioning で、userを追加できるように、shellを作成したので追記しておきます。

useradd.sh
#!/bin/bash
set -Ceu

USER="ocome"
# password "vagrant" を SHA-512 でハッシュ化
COMMAND='print crypt('"${USER}"', "\$6\$");'
PASSWORD=$(perl -e "${COMMAND}")

create_user(){

  echo "Create a user named ${USER}."
  # Create User
  sudo useradd -p ${PASSWORD} -m ${USER}
  # grant authrity
  sudo usermod -G sudo ${USER}
  exit 0
}

trap "create_user" ERR
# check exist user
getent passwd ${USER}

echo "${USER} is already created."
14
19
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
19