I'm trying to debug some Packer configuration I've inherited. One configuration in particular works from our CI pipeline, but does not work locally. One difference is the SSH port used. When I use the default SSH port locally, packer works. When I try to use 5222, I get a timeout:
==> googlecompute: Using ssh communicator to connect: 35.193.105.225
2020/09/17 14:17:56 packer: 2020/09/17 14:17:56 [INFO] Waiting for SSH, up to timeout: 5m0s
==> googlecompute: Waiting for SSH to become available...
2020/09/17 14:18:11 packer: 2020/09/17 14:18:11 [DEBUG] TCP connection to SSH ip/port failed: dial tcp
35.193.105.225:5222: i/o timeout
< .. snip .. >
2020/09/17 14:22:51 packer: 2020/09/17 14:22:51 [DEBUG] TCP connection to SSH ip/port failed: dial tcp
35.193.105.225:5222: i/o timeout
2020/09/17 14:22:56 ui error:
==> googlecompute: Timeout waiting for SSH.
==> googlecompute: Timeout waiting for SSH.
2020/09/17 14:22:56 packer: 2020/09/17 14:22:56 [DEBUG] SSH wait cancelled. Exiting loop.
2020/09/17 14:22:56 ui error:
==> googlecompute: Timeout waiting for SSH.
==> googlecompute: Timeout waiting for SSH.
However, SSH responds from the same machine when I connect myself:
$ ssh 35.193.105.225 -P 5222
The authenticity of host '35.193.105.225 (35.193.105.225)' can't be established.
ECDSA key fingerprint is SHA256:+Cls2Qe932m0yNrDWLbjUfeZcOpORGUT9p9rCjLbotg.
Are you sure you want to continue connecting (yes/no)? ^C
I'm running packer with this command:
PACKER_LOG=1 packer build \
-var "instance_name=${INSTANCE_NAME}" \
-var "shutdown_script=$(cat files/metadata_shutdown_script.sh)" \
-var "startup_script=$(cat files/metadata_startup_script.sh)" \
-var "ssh_private_key_file=${SSH_KEY}" \
-var "ssh_public_keys=root:$(cat "${SSH_KEY}.pub")" \
-on-error=ask \
test.json
test.json looks like this:
{
"variables": {},
"builders": [
{
"image_description": "Custom packer base image for other images, debian based",
"image_family": "debian9-base",
"image_labels": {
"type": "debian-base"
},
"image_name": "debian9-base-{{timestamp}}",
"instance_name": "{{ user `instance_name` }}",
"metadata": {
"block-project-ssh-keys": "TRUE",
"enable-oslogin": "FALSE",
"shutdown-script": "{{user `shutdown_script`}}",
"ssh-keys": "{{user `ssh_public_keys`}}",
"startup-script": "{{user `startup_script`}}"
},
"preemptible": "true",
"project_id": "lana-gitlab",
"scopes": [
],
"source_image_family": "debian-9",
"ssh_port": "5222",
"ssh_username": "packer",
"type": "googlecompute",
"zone": "us-central1-a"
}
]
}
and files/metadata_startup_script.sh looks like this:
set -eufCo pipefail
export SHELLOPTS
IFS=$'\t\n'
cat >| /etc/ssh/sshd_config <<-EOF
# AllowUsers root
LogLevel DEBUG
PasswordAuthentication no
PermitRootLogin prohibit-password
EOF
sshd -t
systemctl reload ssh
If I remove the `"ssh_port": "5222",` from test.json, packer succeeds.
What am I overlooking that's preventing this non-standard SSH port from working?
Thank you.