Skip to content

Instantly share code, notes, and snippets.

@lee-pai-long
Last active September 5, 2017 13:33
Show Gist options
  • Save lee-pai-long/f0ba1f984b069424e70b8c416984946d to your computer and use it in GitHub Desktop.
Save lee-pai-long/f0ba1f984b069424e70b8c416984946d to your computer and use it in GitHub Desktop.
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: hashicorp/vagrant#1753 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment