diff --git a/builder/vagrant/step_ssh_config.go b/builder/vagrant/step_ssh_config.go index 6fb65ccde..7da3cb7d8 100644 --- a/builder/vagrant/step_ssh_config.go +++ b/builder/vagrant/step_ssh_config.go @@ -36,8 +36,6 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi return multistep.ActionHalt } - config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile - config.Comm.SSHUsername = sshConfig.User config.Comm.SSHHost = sshConfig.Hostname port, err := strconv.Atoi(sshConfig.Port) if err != nil { @@ -46,6 +44,14 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi } config.Comm.SSHPort = port + if config.Comm.SSHUsername != "" { + // If user has set the username within the communicator, use the + // auth provided there. + return multistep.ActionContinue + } + config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile + config.Comm.SSHUsername = sshConfig.User + return multistep.ActionContinue }