SSH handshake err: ssh: handshake failed

I have an error and I don’t know how I can get around it. I can’t connect to Linux from a Windows 10 machine.
Packer version v1.9.1
virtual box version 7.0

My json of configuration packer
{
“variables”: {
“version”: “7”
},
“provisioners”: [
{
“type”: “shell”,
“execute_command”: “echo ‘vagrant’ | {{.Vars}} sudo -S -E bash ‘{{.Path}}’”,
“script”: “scripts/ansible.sh”
},
{
“type”: “shell”,
“execute_command”: “echo ‘vagrant’ | {{.Vars}} sudo -S -E bash ‘{{.Path}}’”,
“script”: “scripts/setup.sh”
},
{
“type”: “ansible-local”,
“playbook_file”: “…/shared/main.yml”,
“galaxy_file”: “…/shared/requirements.yml”
},
{
“type”: “shell”,
“execute_command”: “echo ‘vagrant’ | {{.Vars}} sudo -S -E bash ‘{{.Path}}’”,
“script”: “scripts/cleanup.sh”
}
],
“builders”: [
{
“type”: “virtualbox-iso”,
“boot_command”: [
“”,
“install ”,
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
“debian-installer=en_US.UTF-8 ”,
“auto ”,
“locale=en_US.UTF-8 ”,
“kbd-chooser/method=us ”,
“keyboard-configuration/xkb-keymap=us ”,
“netcfg/get_hostname={{ .Name }} ”,
“netcfg/get_domain=vagrantup.com ”,
“fb=false ”,
“debconf/frontend=noninteractive ”,
“console-setup/ask_detect=false ”,
“console-keymaps-at/keymap=us ”,
“grub-installer/bootdev=/dev/sda ”,
“”
],
“boot_wait”: “1m”,
“disk_size”: 81920,
“guest_os_type”: “Debian_64”,
“headless”: false,
“http_directory”: “http”,
“iso_urls”:“https://cdimage.debian.org/cdimage/archive/10.11.0/amd64/iso-cd/debian-10.11.0-amd64-xfce-CD-1.iso”,
“iso_checksum”: “sha256:3e8a66c0fc0fdcec8692a59c0f53fe1a888b18e07e28de53d794f757c43aa360”,
“ssh_username”: “vagrant”,
“ssh_password”: “vagrant”,
“ssh_host_port_min”: 2222,
“ssh_host_port_max”: 2229,
“ssh_port”: 2223,
“ssh_wait_timeout”: “1800s”,
“shutdown_command”: “echo ‘vagrant’|sudo -S shutdown -P now”,
“guest_additions_path”: “VBoxGuestAdditions_{{.Version}}.iso”,
“virtualbox_version_file”: “.vbox_version”,
“vm_name”: “packer-debian-10-amd64”,
“vboxmanage”: [
[
“modifyvm”,
“{{.Name}}”,
“–memory”,
“1024”
],
[
“modifyvm”,
“{{.Name}}”,
“–cpus”,
“1”
]
]
}
],
“post-processors”: [
[
{
“output”: “builds/{{.Provider}}-debian10.box”,
“type”: “vagrant”
}
]
]
}

My Preceed.cfg
choose-mirror-bin mirror/http/proxy string
d-i apt-setup/use_mirror boolean true
d-i base-installer/kernel/override-image string linux-server
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i keymap select us
d-i mirror/country string manual
d-i mirror/http/directory string /debian
d-i mirror/http/hostname string httpredir.debian.org
d-i mirror/http/proxy string
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true
d-i passwd/root-login boolean false
d-i passwd/root-password-again password vagrant
d-i passwd/root-password password vagrant
d-i passwd/user-fullname string vagrant
d-i passwd/user-uid string 1000
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant
d-i pkgsel/include string sudo bzip2 acpid cryptsetup zlib1g-dev wget curl dkms make nfs-common net-tools
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade

Prevent packaged version of VirtualBox Guest Additions being installed:

d-i preseed/early_command string sed -i
‘/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}’
/usr/lib/pre-pkgsel.d/20install-hwpackages
d-i time/zone string UTC
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i preseed/late_command string sed -i ‘/^deb cdrom:/s/^/#/’ /target/etc/apt/sources.list
apt-cdrom-setup apt-setup/cdrom/set-first boolean false
apt-mirror-setup apt-setup/use_mirror boolean true
popularity-contest popularity-contest/participate boolean false
tasksel tasksel/first multiselect standard, ssh-server

and My log of the build
2023/06/22 17:26:22 [INFO] Packer version: 1.9.1 [go1.20.4 windows amd64]
2023/06/22 17:26:22 [TRACE] discovering plugins in C:\ProgramData\chocolatey\lib\packer\tools
2023/06/22 17:26:22 [TRACE] discovering plugins in C:\Users\Quentin\AppData\Roaming\packer.d\plugins
2023/06/22 17:26:22 [DEBUG] Discovered plugin: docker = C:\Users\Quentin\AppData\Roaming\packer.d\plugins\github.com\hashicorp\docker\packer-plugin-docker_v1.0.8_x5.0_windows_amd64.exe
2023/06/22 17:26:22 [DEBUG] Discovered plugin: vmware = C:\Users\Quentin\AppData\Roaming\packer.d\plugins\github.com\hashicorp\vmware\packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe
2023/06/22 17:26:22 [INFO] found external [iso vmx] builders from vmware plugin
2023/06/22 17:26:22 [INFO] found external [-packer-default-plugin-name-] builders from docker plugin
2023/06/22 17:26:22 [INFO] found external [import push save tag] post-processors from docker plugin
2023/06/22 17:26:22 [TRACE] discovering plugins in .
2023/06/22 17:26:22 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/06/22 17:26:22 [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 [WARN] Config file doesn’t exist: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 [INFO] Setting cache directory: C:\Users\Quentin\Desktop\Packer\packer-boxes\debian10\packer_cache
e: cannot determine if process is in background: Process background check error: not implemented yet
2023/06/22 17:26:22 [TRACE] Starting internal plugin packer-builder-virtualbox-iso
2023/06/22 17:26:22 Starting plugin: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe string{“C:\ProgramData\chocolatey\lib\packer\tools\packer.exe”, “plugin”, “packer-builder-virtualbox-iso”}
2023/06/22 17:26:22 Waiting for RPC address for: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe
2023/06/22 17:26:22 packer.exe plugin: [INFO] Packer version: 1.9.1 [go1.20.4 windows amd64]
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [WARN] Config file doesn’t exist: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [INFO] Setting cache directory: C:\Users\Quentin\Desktop\Packer\packer-boxes\debian10\packer_cache
2023/06/22 17:26:22 packer.exe plugin: args: string{“packer-builder-virtualbox-iso”}
2023/06/22 17:26:22 packer.exe plugin: Plugin port range: [10000,25000]
2023/06/22 17:26:22 packer.exe plugin: Plugin address: tcp 127.0.0.1:10000
2023/06/22 17:26:22 packer.exe plugin: Waiting for connection…
2023/06/22 17:26:22 Received tcp RPC address for C:\ProgramData\chocolatey\lib\packer\tools\packer.exe: addr is 127.0.0.1:10000
2023/06/22 17:26:22 packer.exe plugin: Serving a plugin connection…
2023/06/22 17:26:22 [TRACE] Starting internal plugin packer-provisioner-shell
2023/06/22 17:26:22 Starting plugin: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe string{“C:\ProgramData\chocolatey\lib\packer\tools\packer.exe”, “plugin”, “packer-provisioner-shell”}
2023/06/22 17:26:22 Waiting for RPC address for: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe
2023/06/22 17:26:22 packer.exe plugin: [INFO] Packer version: 1.9.1 [go1.20.4 windows amd64]
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [WARN] Config file doesn’t exist: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [INFO] Setting cache directory: C:\Users\Quentin\Desktop\Packer\packer-boxes\debian10\packer_cache
2023/06/22 17:26:22 packer.exe plugin: args: string{“packer-provisioner-shell”}
2023/06/22 17:26:22 packer.exe plugin: Plugin port range: [10000,25000]
2023/06/22 17:26:22 packer.exe plugin: Plugin address: tcp 127.0.0.1:10000
2023/06/22 17:26:22 Received tcp RPC address for C:\ProgramData\chocolatey\lib\packer\tools\packer.exe: addr is 127.0.0.1:10000
2023/06/22 17:26:22 packer.exe plugin: Waiting for connection…
2023/06/22 17:26:22 packer.exe plugin: Serving a plugin connection…
2023/06/22 17:26:22 [TRACE] Starting internal plugin packer-provisioner-shell
2023/06/22 17:26:22 Starting plugin: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe string{“C:\ProgramData\chocolatey\lib\packer\tools\packer.exe”, “plugin”, “packer-provisioner-shell”}
2023/06/22 17:26:22 Waiting for RPC address for: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe
2023/06/22 17:26:22 packer.exe plugin: [INFO] Packer version: 1.9.1 [go1.20.4 windows amd64]
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [WARN] Config file doesn’t exist: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [INFO] Setting cache directory: C:\Users\Quentin\Desktop\Packer\packer-boxes\debian10\packer_cache
2023/06/22 17:26:22 packer.exe plugin: args: string{“packer-provisioner-shell”}
2023/06/22 17:26:22 packer.exe plugin: Plugin port range: [10000,25000]
2023/06/22 17:26:22 packer.exe plugin: Plugin address: tcp 127.0.0.1:10000
2023/06/22 17:26:22 packer.exe plugin: Waiting for connection…
2023/06/22 17:26:22 Received tcp RPC address for C:\ProgramData\chocolatey\lib\packer\tools\packer.exe: addr is 127.0.0.1:10000
2023/06/22 17:26:22 packer.exe plugin: Serving a plugin connection…
2023/06/22 17:26:22 [TRACE] Starting internal plugin packer-provisioner-ansible-local
2023/06/22 17:26:22 Starting plugin: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe string{“C:\ProgramData\chocolatey\lib\packer\tools\packer.exe”, “plugin”, “packer-provisioner-ansible-local”}
2023/06/22 17:26:22 Waiting for RPC address for: C:\ProgramData\chocolatey\lib\packer\tools\packer.exe
2023/06/22 17:26:22 packer.exe plugin: [INFO] Packer version: 1.9.1 [go1.20.4 windows amd64]
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2023/06/22 17:26:22 packer.exe plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [WARN] Config file doesn’t exist: C:\Users\Quentin\AppData\Roaming\packer.config
2023/06/22 17:26:22 packer.exe plugin: [INFO] Setting cache directory: C:\Users\Quentin\Desktop\Packer\packer-boxes\debian10\packer_cache
2023/06/22 17:26:22 packer.exe plugin: args: string{“packer-provisioner-ansible-local”}

2023/06/22 17:35:55 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:35:55 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:35:55 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49183->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:02 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:02 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:02 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:02 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49187->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:09 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:09 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:09 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:09 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49189->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:16 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:16 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:16 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:16 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49191->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:23 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:23 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:23 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:23 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49193->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:30 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:30 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:30 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:30 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49195->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:37 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:37 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:37 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:37 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49200->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:44 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:44 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:44 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:44 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49203->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:51 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:51 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:51 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:51 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49205->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:36:58 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:36:58 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:36:58 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:36:58 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49207->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/22 17:40:48 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2228…
2023/06/22 17:40:48 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/22 17:40:48 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/22 17:40:48 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:49250->127.0.0.1:2228: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.

can you help me or give me some issue because i’m totaly lost

One.

```
Use tildes for posting code
```

Two

Use hcl and not json.

Three

By the end of the boot_command you should have an ssh server running on your liveVM and the user vagrant created with vagrant as it’s password. Do you have that?

Thank’s for your answer.

There is a difference of performence between json and HCL ? why it’s better to choose HCL?

My VM not arrived until live there is a blue screen and waiting for ssh i don’t know why they seems don’t finish the configuration

No. It’s just more readable for me and in general.
It’s the recommended script language by Hashicorp.

During the packer build packer tries to make an ssh connection twice. From host ssh client to liveVM ssh server and from host ssh client to buildVM ssh server.

If you don’t have the liveVM ssh server running and ssh user/password added on the liveVM before the end of the boot_command, you get an SSH timeout.
If you don’t have the buildVM ssh server running and ssh user/password added on the buildVM before a reboot in your scripts or at the end of your last script, you get an SSH timeout.

Can you check if at the end of your preseed.cfg SSH is up and running?
Something like:
d-i systemctl status ssh ?

My HCL code is like this:

# This file was autogenerated by the 'packer hcl2_upgrade' command. We
# recommend double checking that everything is correct before going forward. We
# also recommend treating this file as disposable. The HCL2 blocks in this
# file can be moved to other files. For example, the variable blocks could be
# moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
# suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
# once they also need to be in the same folder. 'packer inspect folder/'
# will describe to you what is in that folder.

# Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
# and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
# executed together and the outcome will be unknown.

# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source. Read the documentation for source blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "virtualbox-iso" "autogenerated_1" {
  boot_command        = ["<esc><wait>", "<esc><wait>", "<enter><wait>", "/install/vmlinuz<wait>", " initrd=/install/initrd.gz", " auto-install/enable=true", " debconf/priority=critical", " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>", " -- <wait>", "<enter><wait>"]
  boot_wait           = "10s"
  guest_os_type       = "ubuntu-64"
  headless            = "false"
  http_directory      = "http"
  iso_checksum        = "sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"
  iso_url             = "http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso"
  shutdown_command    = "echo 'vagrant' | sudo -S shutdown -P now"
  ssh_password        = "vagrant"
  ssh_username        = "vagrant"
  ssh_wait_timeout    = "10000s"
}

# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
  sources = ["source.virtualbox-iso.autogenerated_1"]

  provisioner "shell" {
    inline = ["sudo apt update", "sudo apt -y install vim "]
  }

}

and my preseed is this:

#_preseed_V1
# Automatic installation
d-i auto-install/enable boolean true

# Preseeding only locale sets language, country and locale.
d-i debian-installer/language string fr
d-i debian-installer/country string CH
d-i debian-installer/locale string fr_CH.UTF-8

d-i console-setup/ask_detect boolean false
d-i debconf/frontend select noninteractive

# Keyboard selection.
d-i keyboard-configuration/xkb-keymap select ch
d-i keymap select ch

choose-mirror-bin mirror/http/proxy string
d-i apt-setup/use_mirror boolean true
d-i base-installer/kernel/override-image string linux-server

### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i time/zone string UTC

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

# This is fairly safe to set, it makes grub install automatically to the MBR
# if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true

# This one makes grub-installer install to the MBR if it also finds some other
# OS, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true

# Set dev for grub boot
d-i grub-installer/bootdev string /dev/sda

### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/country string manual
d-i mirror/http/directory string /ubuntu/
d-i mirror/http/hostname string archive.ubuntu.com
d-i mirror/http/proxy string

# This makes partman automatically partition without confirmation.
d-i partman-efi/non_efi_system boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true

### Account setup
d-i passwd/root-login boolean false
d-i passwd/user-fullname string vagrant
d-i passwd/user-uid string 1000
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant

# The installer will warn about weak passwords. If you are sure you know
# what you're doing and want to override it, uncomment this.
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false

### Package selection
tasksel tasksel/first multiselect standard, server
d-i pkgsel/include string openssh-server
d-i pkgsel/install-language-support boolean false

# disable automatic package updates
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade

# Disable polularity contest
popularity-contest popularity-contest/participate boolean false

# Select base install
tasksel tasksel/first multiselect standard, ssh-server

# Setup passwordless sudo for packer user
d-i preseed/late_command string \
echo "vagrant ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/vagrant && chmod 0440 /target/etc/sudoers.d/vagrant
d-i systemctl ssh restart
d-i systemctl status ssh


I Installed OpenSSH Client on My windows

After this code i have a blue screen and it’s seems to not configure the VM but i don’t know why Maybe you can help me?

Do the logs still give the same error?

Yes i have allways the same Issue
thes don’t go further than blocked screen

with this error log

2023/06/23 15:51:11 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:57227->127.0.0.1:2708: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/23 15:51:18 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2708...
2023/06/23 15:51:18 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/23 15:51:18 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/23 15:51:18 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:57233->127.0.0.1:2708: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/23 15:51:25 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2708...
2023/06/23 15:51:25 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/23 15:51:25 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/23 15:51:25 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:57239->127.0.0.1:2708: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/23 15:51:32 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2708...
2023/06/23 15:51:32 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/23 15:51:32 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/23 15:51:32 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:57241->127.0.0.1:2708: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.
2023/06/23 15:51:39 packer.exe plugin: [INFO] Attempting SSH connection to 127.0.0.1:2708...
2023/06/23 15:51:39 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2023/06/23 15:51:39 packer.exe plugin: [DEBUG] handshaking with SSH
2023/06/23 15:51:39 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:57243->127.0.0.1:2708: wsarecv: Une connexion existante a dû être fermée par l’hôte distant.

until the SSH Time out connexion

Your cfg setup looks a lot like my boot_script now
in terms of ssh configurations.

What does the d-i systemctl status ssh say?
Is it up and running?

Can you change this line…

echo "vagrant ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/vagrant && chmod 0440 /target/etc/sudoers.d/vagrant

Into this…

echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /target/etc/sudoers.d/vagrant
echo 'vagrant ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/vagrant
chmod 0440 /target/etc/sudoers.d/vagrant

And can you add a vagrant group to the vagrant user?
Although this might not be necessary,
I’m just looking at the differences between what my boot_script does
and your preseed file.

it works now
I don’t know exactely what the problem was, but I disabled Firewall completely and changed the path for the pressed to configure the machine because it wasn’t working with the url http and preseed.cfg.

source "vmware-iso" "autogenerated_1" {
  floppy_files = ["./http/preseed.cfg"]
  boot_command     = [ 
        "<esc><wait>",
        "<esc><wait>",
        "<enter><wait>",
        "/install/vmlinuz<wait>",
        " initrd=/install/initrd.gz",
        " auto-install/enable=true",
        " debconf/priority=critical",
        " preseed/file=/media/preseed.cfg<wait>",
        "<enter><wait>"
      ]

I used vmWare because they explain much better were is the problem
I’m going to run some tests to find out what the problem was

Thank you for your help

1 Like

Hi,
I have an other problem with the vmware hypersivor this time
the hypervisor VirtualBox works well but not VMWare

My HCL is like this

source "vmware-iso" "autogenerated_1" {
  boot_command                   = [
  "<esc><esc><enter><wait>", 
  "/install/vmlinuz noapic",
  " initrd=/install/initrd.gz",
  " auto=true", 
  " priority=critical",
  " hostname=${var.hostname}",
  " passwd/user-fullname=${var.ssh_fullname}",
  " passwd/username=${var.ssh_username}",
  " passwd/user-password=${var.ssh_password}",
  " passwd/user-password-again=${var.ssh_password}",
  " preseed/file=/media/preseed.cfg<wait>",
  " -- <enter>"]
  boot_wait                      = "5s"
  disk_size                      = "${var.disk_size}"
  floppy_files                   = ["./http/preseed.cfg"]
  headless                       = "${var.headless}"
  http_directory                 = "http"
  iso_checksum                   = "${var.iso_checksum}"
  iso_url                        = "${var.iso_url}"
  shutdown_command               = "echo '${var.ssh_password}' | sudo -S shutdown -P now"
  ssh_password                   = "${var.ssh_password}"
  ssh_timeout                    = "${var.ssh_timeout}"
  ssh_username                   = "${var.ssh_username}"
  version                        = "17"
  vm_name                        = "ubuntu-18.04-LTS-server"
  vmx_remove_ethernet_interfaces = true
}

# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
  sources = ["source.vmware-iso.autogenerated_1"]

  provisioner "shell" {
    execute_command = "echo '${var.ssh_password}'|{{ .Vars }} sudo -E -S bash '{{ .Path }}'"
    inline          = ["sudo apt update", "sudo apt -y install vim "]
  }

  post-processor "vagrant" {
    output               = "./vagrant/linux_18_{{ .Provider }}.box"
    vagrantfile_template = "./Vagrantfile.template"
  }
  post-processor "compress" {
    output = "./VM/{{ .BuildName }}_VM.zip"
  }
}

and the log file is like this i don’t know if it’s due to the plugin ?
it’s working if i want to do a vm with windows 10

2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 Searching for file 'C:/ProgramData/VMware/netmap.conf'
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 Found file 'C:/ProgramData/VMware/netmap.conf'
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 Located networkmapper configuration file using Workstation: C:/ProgramData/VMware/netmap.conf
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 GuestIP discovered device matching nat: vmnet8
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 Lookup up IP information...
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 GuestAddress found MAC address in VMX: 00:0C:29:56:C3:4B
2023/06/29 16:09:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:28 Trying DHCP leases path: C:/ProgramData/VMware/vmnetdhcp.leases
2023/06/29 16:09:43 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:43 Skipping lease entry #1 due to being unable to connect to the host (192.168.10.134) with tcp port (22).
2023/06/29 16:09:58 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:09:58 Skipping lease entry #2 due to being unable to connect to the host (192.168.10.134) with tcp port (22).
2023/06/29 16:10:13 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:10:13 Skipping lease entry #3 due to being unable to connect to the host (192.168.10.134) with tcp port (22).
2023/06/29 16:10:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:10:28 Skipping lease entry #4 due to being unable to connect to the host (192.168.10.134) with tcp port (22).
2023/06/29 16:10:28 packer-plugin-vmware_v1.0.8_x5.0_windows_amd64.exe plugin: 2023/06/29 16:10:28 [DEBUG] Error getting SSH address: Host is not up

My VM is booting but after that nothing happen and is waiting for ssh become available

And SSH on my VM is running

Do you have any Idea about this problem

I’m not familiar with VMWare for packer, the plugin seems like the latest version and the SSH config looks fine, so I don’t see why the SSH connection for VMWare would fail either.

I’m a bit confused about the logs though.
Host is not up → Does it refer to the VM or the actual host OS?

Do you have any firewalls running on port 22?
Try changing the port to 2222. Maybe that will work.

What do you mean by this?
That you can get an SSH connection through a regular VM?