SSH onto Vagrant Box With Different Username

后端 未结 4 1237
梦如初夏
梦如初夏 2020-12-22 22:46

Rather than ssh-ing onto my Vagrant virtual machine with a \"vagrant\" user-name and password, I\'d like to use kevin/kevin.

I modified my Vagrantfile t

4条回答
  •  独厮守ぢ
    2020-12-22 23:14

    Another solution, after adding user to Vagrant via your provisioning script:

    ## add kevin
    useradd -m -s /bin/bash -U kevin -u 666 --groups wheel
    cp -pr /home/vagrant/.ssh /home/kevin/
    chown -R kevin:kevin /home/kevin
    echo "%kevin ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/kevin
    

    add this to your Vagrant file:

    VAGRANT_COMMAND = ARGV[0]
    if VAGRANT_COMMAND == "ssh"
      config.ssh.username = 'kevin'
    end
    

    Now Vagrant will use default vagrant user to provision your VM, but once it's up, you can use simple vagrant ssh to log in as kevin via default Vagrant ssh-key.

    This way you can ship your desired Vagrantfile and users just say vagrant up and kevin automatically becomes ready to use.

提交回复
热议问题