mirror of
https://github.com/LamGC/quickly-conf-sshd.git
synced 2025-11-27 22:06:55 +00:00
feat: 在更新完 authorized_keys 后, 清除首尾空行.
This commit is contained in:
17
conf-sshd.sh
17
conf-sshd.sh
@ -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')"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user