linux添加公钥,添加到 Linux VM 上的授权密钥文件的外来 SSH 公钥

通过使用具有受保护的设置的扩展或托管标识部署的 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 文件以确保仅存在已知公钥。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值