关于如何在Vagrant下使用root用户登录的问题

来源:6-4 水平扩展和负载均衡

Kokutou

2018-03-04

参见如下链接:

vagrant的centos镜像,怎么用root用户登录?

附上我的Vagrantfile文件内容以便参考:

Vagrant.require_version ">= 1.6.0"
boxes = [
    {
        :name => "CentOS7",
        :eth1 => "192.168.205.10",
        :mem => "1024",
        :cpu => "1"
    }
]
Vagrant.configure(2) do |config|
   # additions version when booting this machine
  config.vbguest.auto_update = false
  # do NOT download the iso file from a webserver
  config.vbguest.no_remote = true
  config.vm.box = "centos7"
  config.ssh.username = 'root'
  config.ssh.password = 'vagrant'
  config.ssh.insert_key = 'true'
  boxes.each do |opts|
    config.vm.define opts[:name] do |config|
      config.vm.hostname = opts[:name]
      config.vm.provider :parallels do |prl|
        prl.memory = opts[:mem]
        prl.cpus = opts[:cpu]
      end
      config.vm.network :private_network, ip: opts[:eth1]
    end
  end
  config.vm.synced_folder "./labs", "/home/vagrant/labs",:nfs => true
end

主要就是这三行代码

config.ssh.username = 'root'
config.ssh.password = 'vagrant' 
config.ssh.insert_key = 'true'

Vagrantfile里面的内容不要照抄,因为我用的虚拟机不是VirtualBox。

另外,下面这行

  config.vm.synced_folder "./labs", "/home/vagrant/labs",:nfs => true

:nfs => true是用来开启NFS文件系统提升Vagrant共享目录性能的。

写回答

1回答

麦兜搞IT

2018-03-04

您好,很棒。默认的用户名密码一般是vagrant/vagrant,这个用户也是具有sudo权限的。

0
1
Kokutou
非常感谢!
2018-03-04
共1条回复

系统学习Docker 践行DevOps理念

无论你是开发、测试还是运维,Docker都是你的必备技能。

3297 学习 · 1896 问题

查看课程