terraform
network_error
ai_generated
true
错误:无法连接到远程主机:拨号 tcp <ip>:22:连接被拒绝
Error: Failed to connect to the remote host: dial tcp <ip>:22: connect: connection refused
ID: terraform/provisioner-connection-refused
90%修复率
88%置信度
1证据数
2023-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.4.0 | active | — | — | — |
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
根因分析
Terraform provisioner 无法建立 SSH 连接,因为远程主机未在端口 22 上监听或 IP 不可达。
English
Terraform provisioner cannot establish SSH connection because the remote host is not listening on port 22 or the IP is unreachable.
官方文档
https://developer.hashicorp.com/terraform/language/resources/provisioners/connection解决方案
-
验证安全组允许端口 22 的入站流量,并且实例具有公共 IP。使用 'ssh -vvv user@ip' 测试连接。
-
检查实例是否已启动并且 SSH 服务正在运行。使用 cloud-init 日志或控制台输出进行验证。
无效尝试
常见但无效的做法:
-
95% 失败
Simply retrying the apply command does not resolve the underlying network issue; the host is still unreachable.
-
70% 失败
Adding more timeout in the connection block does not fix the refusal; it only delays the failure.