SSH onto Vagrant Box With Different Username

后端 未结 4 1236
梦如初夏
梦如初夏 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:29

    You can ssh to the box using vagrant but NOT kevin, that's expected.

    Most Vagrant base boxes have only 2 users with SSH access, root and vagrant. They both use vagrant as password, in addition, vagrant is configured for public key authentication using the insecure (why? see Vagrant insecure by default?) key pair provided in the Vagrant project on GitHub.

    To be able to login as kevin, you'll have to ssh into the box and create the user (useradd -m -s /bin/bash -U kevin) first, configure public key authentication (many ways e.g ssh-copy-id, I'll leave it to you.)

    You should be able to ssh into the box after creating the user using vagrant ssh if you properly set config.ssh.username in Vagrantfile.

    Of course you can manually ssh into the box by (assume NAT is in use)

    ssh -p 2222 kevin@localhost

    or (on Linux)

    ssh -p 2222 -i /opt/vagrant/embedded/gems/gems/vagrant-1.5.1/keys/vagrant.pub vagrant@localhost

提交回复
热议问题