Vagrant – Changing the ssh connection password with the machine


Well folks, I'm doing some tests with virtual machines made with Vagrant, but now, I'm having a problem which is to change the default password for connection with the virtual machine (Default password: "vagrant").

Below is the Vagrantfile:

Vagrant.configure(2) do |config| = ""
  config.ssh.username = "vagrant"
  config.ssh.password = '123'
  config.ssh.insert_key = true "public_network", bridge: "wlan0", ip: "" 
  config.vm.provider "virtualbox" do |v| = ""
    v.cpus = 1
    v.memory = 512

Note that I changed the password via config.ssh.password, but when I try to connect via ssh from the terminal, the password remains the default "vagrant".

When I change the username (config.ssh.username) to "root", for example, it gives this problem:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address:
    default: SSH username: root
    default: SSH auth method: password
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
root@'s password:

Well, all that's left is to fix this problem, thanks for the help!


According to the documentation for VagrantFile , the value of the config.ssh.password key is used when logging into the virtual machine via SSH and not for setting the password itself. The password is defined in the image ( box ) you are using. The same explanation goes for the config.ssh.username key.

If you wanted to change your virtual machine's password, you can log in normally to the VM for the first time and only then change the password:

$ vagrant ssh
$ passwd
Changing password for vagrant.
Old Password:
New Password:
Confirm New Password:

After this step change the config.ssh.password to the password you just defined inside the VM.

Scroll to Top