Skip to content

Commit 4fbe379

Browse files
aamirrasheedclaude
andcommitted
Fix SSH key count: use grep -c instead of wc -l to ignore blank lines
The verify command used wc -l to count authorized SSH keys, which counts blank lines too. Changed to grep -c '^ssh-' so only actual key lines are counted. Also use printf in assign to avoid trailing blank lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2fcac4c commit 4fbe379

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

privateclaw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ cmd_verify() {
277277

278278
# -- Check 3: External Access Lockout --
279279
echo "[3/3] External Access Lockout"
280-
KEY_COUNT=$(wc -l < "$ADMIN_HOME/.ssh/authorized_keys" 2>/dev/null | tr -d ' ')
280+
KEY_COUNT=$(grep -c '^ssh-' "$ADMIN_HOME/.ssh/authorized_keys" 2>/dev/null || echo 0)
281281
KEY_COUNT="${KEY_COUNT:-0}"
282282
echo " SSH keys: $KEY_COUNT authorized"
283283
if command -v ufw &>/dev/null; then
@@ -352,7 +352,7 @@ cmd_assign() {
352352

353353
# 1. Set SSH key (clean slate -- only user's key)
354354
mkdir -p /home/$ADMIN_USER/.ssh
355-
echo "$SSH_KEY" > /home/$ADMIN_USER/.ssh/authorized_keys
355+
printf '%s\n' "$SSH_KEY" > /home/$ADMIN_USER/.ssh/authorized_keys
356356
chown -R $ADMIN_USER:$ADMIN_USER /home/$ADMIN_USER/.ssh
357357
chmod 700 /home/$ADMIN_USER/.ssh
358358
chmod 600 /home/$ADMIN_USER/.ssh/authorized_keys

0 commit comments

Comments
 (0)