feat: 在更新完 authorized_keys 后, 清除首尾空行.

This commit is contained in:
2025-10-29 18:40:43 +08:00
parent a7a4f7bd6d
commit e381e78c0f

View File

@ -141,6 +141,23 @@ update_sshkeys() {
mv "$new_auth_file" "$auth_file" mv "$new_auth_file" "$auth_file"
rm -f "$dl_tmp_file" rm -f "$dl_tmp_file"
local final_tmp_file=~/.ssh/authorized_keys.final.tmp
awk '
NR==FNR {
if(NF>0) {
if(first==0) first=NR;
last=NR
}
next
}
FNR >= first && FNR <= last {
print
}
' "$auth_file" "$auth_file" > "$final_tmp_file"
mv "$final_tmp_file" "$auth_file"
chmod 600 "$auth_file" chmod 600 "$auth_file"
echo "SSH public key updated successfully (managed block only) at $(date '+%Y-m-d %H:%M:%S')" echo "SSH public key updated successfully (managed block only) at $(date '+%Y-m-d %H:%M:%S')"
} }