通过使用具有受保护的设置的扩展或托管标识部署的 VM
使用以下脚本从通过扩展或托管标识部署 VM 的证书中移除公钥。 这不会移除部署 VM 时或当使用密钥保管库密钥部署 VM 时指定的密钥。
重要说明
建议在运行此脚本之前对 authorized_keys 文件进行备份。
#!/bin/bash
set -e
# /var/lib/waagent has *.crt files that include the crt files corresponding to
# the user provided public keys and one additional .crt file from MSI.
# This script converts the content of the .crt file into the ssh public key and
# remove it from the authorized_keys file
readarray -t CRT_FILES <
for ((i=0; i < ${#CRT_FILES[@]}; i++))
do
PUBKEY=$(openssl x509 -in "${CRT_FILES[$i]}" -pubkey -noout | ssh-keygen -f /dev/stdin -i -m PKCS8)
sed -i -e "\@$PUBKEY@d" $HOME/.ssh/authorized_keys
Done
运行脚本之后,检查 ssh/authorized_keys 文件以确保仅存在已知公钥。