Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vagrant login as root by default

Problem: frequently the first command I type to my boxes is su -.

Question: how do I make vagrant ssh use the root user by default?

Version: vagrant 1.6.5

like image 668
Mike D Avatar asked Sep 10 '14 06:09

Mike D


People also ask

What is vagrant root password?

Root Password: "vagrant"

What is the vagrant login?

Command: vagrant login The login command is used to authenticate with the HashiCorp's Vagrant Cloud server. Logging in is only necessary if you are accessing protected boxes or using Vagrant Share.


3 Answers

This is useful:

sudo passwd root

for anyone who's been caught out by the need to set a root password in vagrant first

like image 73
Ed Williams Avatar answered Oct 23 '22 18:10

Ed Williams


Solution:
Add the following to your Vagrantfile:

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

When you vagrant ssh henceforth, you will login as root and should expect the following:

==> mybox: Waiting for machine to boot. This may take a few minutes...
    mybox: SSH address: 127.0.0.1:2222
    mybox: SSH username: root
    mybox: SSH auth method: password
    mybox: Warning: Connection timeout. Retrying...
    mybox: Warning: Remote connection disconnect. Retrying...
==> mybox: Inserting Vagrant public key within guest...
==> mybox: Key inserted! Disconnecting and reconnecting using new SSH key...
==> mybox: Machine booted and ready!

Update 23-Jun-2015: This works for version 1.7.2 as well. Keying security has improved since 1.7.0; this technique overrides back to the previous method which uses a known private key. This solution is not intended to be used for a box that is accessible publicly without proper security measures done prior to publishing.

Reference:

  • https://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html
like image 32
Mike D Avatar answered Oct 23 '22 20:10

Mike D


This works if you are on ubuntu/trusty64 box:

vagrant ssh

Once you are in the ubuntu box:

sudo su

Now you are root user. You can update root password as shown below:

sudo -i
passwd

Now edit the below line in the file /etc/ssh/sshd_config

PermitRootLogin yes

Also, it is convenient to create your own alternate username:

adduser johndoe

Wait until it asks for password.

like image 41
Thyag Avatar answered Oct 23 '22 20:10

Thyag