Communityコーディング&開発github.com

SSH Doctor

SSHトリアージ:リモートログイン、launchd sshd、認証前の切断、古いセッションの問題を診断・修正します。

SSH Doctor とは?

SSH Doctorは、macOSにおけるSSH接続のトラブルシューティングを支援するエキスパートスキルです。認証前に接続が切断される、リモートログインが有効に見えるが使用できない、ローカルまたはリモートのMacでSSHの問題が発生した場合に診断を行います。まずローカルループバックテストでsshd/launchd設定の問題を切り分け、成功すればネットワーク/ファイアウォールの問題を調査する段階的なアプローチを取ります。また、古くなったsshd-sessionプロセスが原因で新しい接続がブロックされる問題の特定と修正、sshd_configの不審な設定行の報告、OPサービスアカウントトークンの安全な転送などもサポートします。このスキルはClaude CodeやCodexなどのAIエージェントプラットフォームで使用することを想定しており、秘密情報を出力せず、変更前の確認を徹底する安全設計がなされています。

対応~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が認証前に接続してから切断する場合、Remote Loginが利用可能と表示されているが使用できない場合、またはローカル/リモートのMac SSHの診断が必要な場合に使用します。

ルール

  • シークレット、トークン、完全な環境変数、または広範囲なgrep出力を出力しないでください。
  • 最初にローカルで検証します。ループバックが失敗した場合はサーバー側のsshd/launchd/configの問題です。ループバックが成功しリモートが失敗する場合は、ネットワーク/ファイアウォール/フィルター/リッスンパスの問題です。
  • /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 の一時ファイルにリダイレクトします
  • トークンを決してエコーしないでください

存在確認:

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.

関連スキル