"gcloud 应用程序实例 ssh"命令禁用 SSH 主机密钥检查



假设我有一些命令/脚本要在我的gcloud应用程序实例上执行:

gcloud app instances ssh --quiet 
--version=${version} --service=${service} ${instance_id} --container=gaeapp -- 
bash commands.sh

如何禁用SSH主机密钥检查gcloud app instances ssh?因为目前我有以下结果:

Executing command in container blah-blah (version=20180813t144010, service=default)
...
Sending public key to instance [apps/blah-blah].
Waiting for operation [apps/blah-blah] to complete...done.                                   
The authenticity of host 'apps/blah-blah (123.123.123.123)' can't be established.
ECDSA key fingerprint is SHA256:....
Are you sure you want to continue connecting (yes/no)?

我的解决方法是在运行命令之前创建 ssh 指纹:

INSTANCE_NAME=$(gcloud app instances list --service="$RUN_SERVICE" --version="$CI_COMMIT_SHORT_SHA" --project="$PROJECT_ID" --format="value(ID)" --limit=1)
INSTANCE_IP=$(gcloud app instances list --service="$RUN_SERVICE" --version="$CI_COMMIT_SHORT_SHA" --project="$PROJECT_ID" --format="value(instance.vmIp)" --limit=1)
ssh-keyscan -t ed25519  "$INSTANCE_IP" | sed "s/$INSTANCE_IP/gae.$PROJECT_ID.$INSTANCE_NAME/g" >> ~/.ssh/google_compute_known_hosts

我还发现了另一个问题,您无法使用"root"用户登录,因此,如果您登录的当前帐户是root,它将尝试在目标计算机上创建一个登录名,该登录名也称为root,默认情况下是禁止的。所以我的解决方法是将这一切包装成一个su some-other-user -c 'bash my_script.sh'

目前没有这方面的选项,但您可以在公共问题跟踪器上提出功能请求。

最新更新