Community코딩 & 개발github.com

steipete/ssh-doctor

SSH 문제 진단: 원격 로그인, launchd sshd, 인증 전 연결 종료, 오래된 세션 등을 해결합니다.

ssh-doctor란 무엇인가요?

SSH Doctor는 Mac 시스템에서 SSH 연결이 인증 전에 갑자기 종료되거나, 시스템 설정에서 '원격 로그인'이 켜져 있어도 실제로 연결이 안 되는 문제를 체계적으로 진단하고 해결하는 AI 에이전트 스킬입니다. 먼저 로컬 루프백(127.0.0.1) 테스트로 서버 자체 문제인지, 네트워크/방화벽 문제인지 구분합니다. 이후 sshd 설정 파일에서 AllowUsers/DenyUsers/ListenAddress 등 의심스러운 설정을 검사하고, 로그를 분석하여 launchd가 inetd 세션 생성을 거부하는 'Too many processes' 오류를 찾아냅니다. 또한 오래된 sshd-session 프로세스를 정리하고, macOS 방화벽(socketfilterfw, pfctl) 상태를 확인하며, 필요 시 OP_SERVICE_ACCOUNT_TOKEN을 안전하게 복사하는 기능까지 제공합니다. CLI 기반의 Cursor, Claude Code, Codex 등에서 사용할 수 있으며, 모든 작업은 기밀 정보를 노출하지 않도록 주의합니다.

지원 대상~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/steipete/agent-scripts/tree/main/skills/ssh-doctor

Installed? Explore more 코딩 & 개발 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

SSH Doctor

SSH가 인증 전에 연결을 종료하거나, '원격 로그인'이 활성화된 것처럼 보이지만 실제로 사용할 수 없거나, 로컬/원격 Mac SSH 진단이 필요할 때 사용합니다.

규칙

  • 비밀번호, 토큰, 전체 환경 변수, 또는 광범위한 비밀 검색 결과를 출력하지 마십시오.
  • 먼저 로컬에서 검증하세요: 루프백 실패는 서버 측 sshd/launchd/설정 문제를 의미하고, 루프백 성공 후 원격 실패는 네트워크/방화벽/필터/수신 경로 문제를 의미합니다.
  • /etc/ssh/sshd_config를 변경하기 전에 의심스러운 설정 라인을 보고하세요.
  • 비대화형 SSH를 선호합니다:
ssh -o RequestTTY=no -o RemoteCommand=none HOST 'hostname; id -un'

기본 확인

hostname; id -un; sw_vers
ipconfig getifaddr en0
ipconfig getifaddr en1 2>/dev/null || true
ipconfig getifaddr en7 2>/dev/null || true
sudo systemsetup -getremotelogin
sudo systemsetup -setremotelogin on
sudo launchctl print system/com.openssh.sshd 2>&1 | head -80
sudo launchctl kickstart -k system/com.openssh.sshd
sudo lsof -nP -iTCP:22 -sTCP:LISTEN
nc -vz 127.0.0.1 22
ssh -4 -F /dev/null -o RequestTTY=no -o RemoteCommand=none [email protected] 'hostname; id -un'

비밀번호 대체가 멈추거나 프롬프트를 띄울 때만 BatchMode=yes를 사용하십시오.

설정

sudo sshd -T 2>&1 | egrep -i '^(allowusers|denyusers|allowgroups|denygroups|listenaddress|maxstartups|logingracetime|usepam|passwordauthentication|pubkeyauthentication|authenticationmethods)'
sudo egrep -n '^[[:space:]]*(AllowUsers|DenyUsers|AllowGroups|DenyGroups|Match|MaxStartups|LoginGraceTime|ListenAddress|AuthenticationMethods|UsePAM|PasswordAuthentication|PubkeyAuthentication)\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null || true

의심스러운 항목:

  • DenyUsers가 대상 사용자와 일치하는 경우
  • 제한적인 AllowUsers / AllowGroups
  • 실수로 적용된 Match 블록
  • 매우 작은 MaxStartups
  • 매우 작은 LoginGraceTime
  • 대상 인터페이스가 누락된 ListenAddress

로그

sudo log show --last 30m --predicate 'process == "sshd" OR process == "launchd"' --style compact | tail -160

중요한 Mac 증상:

  • 클라이언트: kex_exchange_identification: Connection closed by remote host
  • 서버 로그: Could not create new instance of inetd service: 67: Too many processes
  • launchctl print system/com.openssh.sshd: 높은 copy count
  • PID 1을 부모로 하는 많은 sshd-session: USER 프로세스

이는 launchd가 TCP 연결은 수락했지만, 추가 sshd inetd 복제본을 생성하는 것을 거부했음을 의미합니다.

오래된 sshd-session 수정

먼저 점검:

sudo launchctl print system/com.openssh.sshd 2>&1 | egrep 'active count|copy count|state =|last exit code|runs ='
ps -axo pid,ppid,uid,user,state,lstart,etime,comm,args | awk '/sshd-session:/ && !/awk/ {print}'
sudo lsof -nP -c sshd-session -iTCP 2>/dev/null | head -120

오래된 세션이 명확히 버려져 새로운 SSH 연결을 차단하는 경우, 선택한 명령줄 일치 항목으로 종료합니다:

ps -axo pid=,args= | awk '/sshd-session: / && !/awk/ {print $1}' | xargs sudo kill -TERM
sleep 2
ps -axo pid=,args= | awk '/sshd-session: / && !/awk/ {print}'

TERM으로도 제거되지 않는 경우, KILL을 사용하기 전에 소유권과 활성 셸을 다시 확인하십시오.

방화벽

루프백은 작동하지만 원격이 실패하는 경우에만:

sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --listapps | grep -i ssh -A2 -B2 || true
sudo pfctl -sr 2>/dev/null | head -80
sudo pfctl -si 2>/dev/null | head -80

또한 수신 주소와 대상 인터페이스를 확인하세요:

ifconfig | awk '/^[a-z0-9]+:/{iface=$1; sub(":","",iface)} iface ~ /^en[0-9]+$/ && /inet / {print iface, $2}'
sudo lsof -nP -iTCP:22 -sTCP:LISTEN

OP 프로필 블록

~/.profile에 다른 호스트에서 복사한 Codex 관리 OP_SERVICE_ACCOUNT_TOKEN이 있는지 확인하라는 요청을 받은 경우:

  • 값을 출력하지 않고 정확한 변수/마커를 확인합니다.
  • 일치하는 라인/블록만 복사합니다.
  • chmod 600 임시 파일을 통해 리디렉션합니다.
  • 토큰을 echo로 출력하지 마십시오.

존재 확인:

awk 'BEGIN{b=0;e=0;x=0} /BEGIN Codex-managed OP_SERVICE_ACCOUNT_TOKEN/ {b=1} /END Codex-managed OP_SERVICE_ACCOUNT_TOKEN/ {e=1} /^[[:space:]]*(export[[:space:]]+)?OP_SERVICE_ACCOUNT_TOKEN=/ {x=1} END{print "marker_begin", b; print "marker_end", e; print "exact_var", x}' ~/.profile

원격 호스트에서 추가:

tmpfile=$(mktemp /tmp/codex-op-token.XXXXXX)
chmod 600 "$tmpfile"
ssh -o RequestTTY=no -o RemoteCommand=none HOST 'awk '\''/^[[:space:]]*(export[[:space:]]+)?OP_SERVICE_ACCOUNT_TOKEN=/ {print; exit}'\'' ~/.profile' > "$tmpfile"
if [ -s "$tmpfile" ]; then
  {
    printf '\n# BEGIN Codex-managed OP_SERVICE_ACCOUNT_TOKEN\n'
    sed -n '1p' "$tmpfile"
    printf '# END Codex-managed OP_SERVICE_ACCOUNT_TOKEN\n'
  } >> ~/.profile
fi
rm -f "$tmpfile"

마무리

보고 항목:

  • 근본 원인
  • 변경된 정확한 명령어
  • 필요한 경우 수정된 검증 출력
  • 원격 재시도 여부

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

steipete/agent-transcript

GitHub PR/issue agent transcripts: redact, preview, and insert safely.

steipete/beeper

Beeper cache: contact hints, room lookup, WhatsApp/iMessage traces, FTS.

steipete/browser-use

Existing Chrome automation: Chrome plugin first, mcporter fallback.

steipete/clawsweeper-status

ClawSweeper status: URLs, workflow health, active workers, ops snapshot.

steipete/clickclack

ClickClack ops: chat app, Hetzner deploy, DNS/docs/app, Docker rollout.

steipete/cloudflare-registrar

Cloudflare Registrar: domain availability, prices, registration via mcporter.

steipete/codex-debugging

Codex debugging: codex-rs core/tui/exec/cli/app-server/config.

steipete/create-cli

CLI UX/spec: args, flags, help, output, errors, config, dry-run.

steipete/discord-clawd

Discord-backed OpenClaw agent/session relay; not archive search.

steipete/domain-dns-ops

DNS/domain ops: registrars, zones, redirects, DNS/HTTP verify, manager truth.

steipete/frontend-design

Frontend UI: pages, apps, components, polished non-generic design.

steipete/github-author-context

GitHub contributor context: identity, activity, trust, company/team signal.

steipete/github-cache-hygiene

GitHub quota/cache hygiene: gh, ghx, xcache, gitcrawl, mirrors, limits.

steipete/github-deep-review

GitHub deep review: bugs, PRs, best fix, stale-or-real, read code first.

steipete/github-project-triage

GitHub issue/PR triage: queues, CI, blockers, risk, proof, next actions.

steipete/hopper-debugger

Hopper debugging: macOS/iOS binaries, ObjC/Swift symbols, dyld, LLDB.

steipete/instruments-profiling

Instruments/xctrace profiling: macOS/iOS traces, binaries, args, exports.

steipete/mac-maintenance

Mac upkeep: brew update/upgrade, pull clean repos, empty Trash.

steipete/maintainer-orchestrator

Open-source maintainer orchestration: Codex app workers, work recovery, dependencies, vision, releases.

steipete/markdown-converter

Markdown conversion: PDF, Office, HTML, data, OCR, audio, ZIP, YouTube.

관련 스킬