lee-pai-long
3/2/2017 - 2:25 PM

How to use the vagrant ssh command with another user than vagrant.

How to use the vagrant ssh command with another user than vagrant.

[VAGRANT] Vagrant ssh connect with another user

Requirement: The other user must be provisioned at boot

Then In the Vagrantfile:

...
VAGRANT_COMMAND = ARGV[0]
...
Vagrant.configure("2") do |config|
...
  if VAGRANT_COMMAND == "ssh"
      config.ssh.username = 'other_username'
  end
...
end

Therefore the provisioning will go normally(with vagrant or root), but the vagrant ssh command will use 'another_user'.

It can be usefull to allow each user with it's own ssh identity but still use a standard box instead of a custom one.

source: https://github.com/mitchellh/vagrant/issues/1753#issuecomment-53970750