From e381e78c0fe44062d6f5ddd25b8b9d271fd17133 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 29 Oct 2025 18:40:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E6=9B=B4=E6=96=B0=E5=AE=8C=20?= =?UTF-8?q?authorized=5Fkeys=20=E5=90=8E,=20=E6=B8=85=E9=99=A4=E9=A6=96?= =?UTF-8?q?=E5=B0=BE=E7=A9=BA=E8=A1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf-sshd.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/conf-sshd.sh b/conf-sshd.sh index 915e240..ff19546 100755 --- a/conf-sshd.sh +++ b/conf-sshd.sh @@ -141,6 +141,23 @@ update_sshkeys() { mv "$new_auth_file" "$auth_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" echo "SSH public key updated successfully (managed block only) at $(date '+%Y-m-d %H:%M:%S')" }