fix(deploy): 无损传输证书同步 SSH 公钥
将包含空格与注释的 Ed25519 host key、公钥先 Base64 编码为单个 SSH 参数,远端解码后再次校验,并清理前次失败产生的无效 authorized_keys 单词行。 验证:Base64 完整往返、bash -n、ShellCheck,两次首次连接失败现场。
This commit is contained in:
@@ -12,6 +12,7 @@ hongkong_host_key=$(cluster_ssh "$CLUSTER_HONGKONG_HOST" \
|
|||||||
echo 'invalid Hong Kong SSH host key' >&2
|
echo 'invalid Hong Kong SSH host key' >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
hongkong_host_key_b64=$(printf '%s' "$hongkong_host_key" | base64 | tr -d '\n')
|
||||||
|
|
||||||
public_key=$(cluster_ssh "$CLUSTER_NINGBO_HOST" 'bash -s' <<'REMOTE'
|
public_key=$(cluster_ssh "$CLUSTER_NINGBO_HOST" 'bash -s' <<'REMOTE'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -26,18 +27,22 @@ REMOTE
|
|||||||
echo 'invalid certificate sync public key' >&2
|
echo 'invalid certificate sync public key' >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
cluster_ssh "$CLUSTER_HONGKONG_HOST" bash -s -- "$public_key" <<'REMOTE'
|
public_key_b64=$(printf '%s' "$public_key" | base64 | tr -d '\n')
|
||||||
|
cluster_ssh "$CLUSTER_HONGKONG_HOST" bash -s -- "$public_key_b64" <<'REMOTE'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
public_key=$1
|
public_key=$(printf '%s' "$1" | base64 -d)
|
||||||
|
[[ $public_key == ssh-ed25519\ * ]]
|
||||||
install -d -m 0700 /root/.ssh
|
install -d -m 0700 /root/.ssh
|
||||||
touch /root/.ssh/authorized_keys
|
touch /root/.ssh/authorized_keys
|
||||||
chmod 0600 /root/.ssh/authorized_keys
|
chmod 0600 /root/.ssh/authorized_keys
|
||||||
|
sed -i '/^ssh-ed25519$/d' /root/.ssh/authorized_keys
|
||||||
grep -Fqx "$public_key" /root/.ssh/authorized_keys || printf '%s\n' "$public_key" >>/root/.ssh/authorized_keys
|
grep -Fqx "$public_key" /root/.ssh/authorized_keys || printf '%s\n' "$public_key" >>/root/.ssh/authorized_keys
|
||||||
REMOTE
|
REMOTE
|
||||||
|
|
||||||
cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$hongkong_host_key" <<'REMOTE'
|
cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$hongkong_host_key_b64" <<'REMOTE'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
hongkong_host_key=$1
|
hongkong_host_key=$(printf '%s' "$1" | base64 -d)
|
||||||
|
[[ $hongkong_host_key == ssh-ed25519\ * ]]
|
||||||
install -d -m 0700 /root/.ssh
|
install -d -m 0700 /root/.ssh
|
||||||
known_hosts=/root/.ssh/known_hosts
|
known_hosts=/root/.ssh/known_hosts
|
||||||
temporary=$(mktemp /root/.ssh/known_hosts.XXXXXX)
|
temporary=$(mktemp /root/.ssh/known_hosts.XXXXXX)
|
||||||
|
|||||||
Reference in New Issue
Block a user