Vagrant - Changing the ssh connection password with the machine

Asked

Viewed 724 times

3

Well people, I’m doing some tests with virtual machines made with Vagrant, but now, I’m having a problem that is to change the default password connection with the virtual machine(Default password: "Vagrant").

Below is the Vagrantfile:

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

Note that I changed the password by config.ssh.password, but when I try to connect by ssh through 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: 127.0.0.1:2222
    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.
[email protected]'s password:

Well, just need to fix this problem, I appreciate the help!

1 answer

1

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

In case you wanted to modify the password of your virtual machine you can first login normally in the VM 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 for the password you just set within the VM.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.