我正在尝试连接到 GCP 实例,该实例每次重新启动时都会更改其公共 IP。要动态获取 IP,我使用以下gcloud命令:
gcloud compute instances describe <vm-name> --zone europe-west --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
Run Code Online (Sandbox Code Playgroud)
然后我有这个ssh config文件:
Host MyHost
ProxyCommand ~/.ssh/vm-connect
Run Code Online (Sandbox Code Playgroud)
vm-connect它指向具有以下内容的脚本
#!/bin/bash
get_host() {
gcloud compute instances describe <vm-name> --zone europe-west1-b --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
}
ssh minikf@$(get_host)
Run Code Online (Sandbox Code Playgroud)
如果我只运行脚本,它就会成功连接到虚拟机。但如果我运行ssh MyHost它会给我:
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: SSH-2.0-OpenSSH_8.2p1: command not found
Run Code Online (Sandbox Code Playgroud)