Claude Code SSH接続エラーを3ステップで解決するガイド¶
この記事の対象者
- リモート開発環境でClaude Codeを使用したい中級者
この記事のポイント¶
- SSH接続エラーの根本原因を特定できる
- 適切な設定ファイルを作成できる
- 接続テストで動作確認できる
問題の核心¶
Claude CodeでSSH接続時に発生する「Permission denied」「Connection refused」エラーは、主に鍵認証の設定不備やSSHサーバー設定の問題が原因です。一般的なSSH設定では動作しないClaude Code特有の要件があります。
解決方法¶
ステップ1: SSH鍵ペアの生成と配置¶
Claude Code用に専用のSSH鍵を生成し、正しい場所に配置します。
# Claude Code専用鍵を生成
ssh-keygen -t ed25519 -f ~/.ssh/claude_code_key -C "claude-code@your-domain.com"
# 適切な権限を設定
chmod 600 ~/.ssh/claude_code_key
chmod 644 ~/.ssh/claude_code_key.pub
ステップ2: SSH設定ファイルの作成¶
~/.ssh/configに Claude Code用の接続設定を追加します。
# Claude Code接続設定
Host claude-remote
HostName your-remote-server.com
User your-username
IdentityFile ~/.ssh/claude_code_key
IdentitiesOnly yes
ServerAliveInterval 60
ステップ3: 公開鍵の登録とテスト¶
リモートサーバーに公開鍵を登録し、接続をテストします。
# 公開鍵をリモートサーバーに転送
ssh-copy-id -i ~/.ssh/claude_code_key.pub your-username@your-remote-server.com
# 接続テスト
ssh claude-remote
よくあるトラブルと対処法¶
| 症状 | 原因 | 解決策 |
|---|---|---|
| Permission denied | 鍵ファイルの権限が不適切 | chmod 600 ~/.ssh/claude_code_key |
| Connection refused | SSHサーバーが起動していない | sudo systemctl start ssh |
| Host key verification failed | known_hostsファイルの不整合 | ssh-keygen -R hostname |
詳細設定(上級者向け・クリックで展開)
### Claude Code特有の要件 - `IdentitiesOnly yes`: 他の鍵との競合を防ぐ - `ServerAliveInterval 60`: 接続の維持設定 - 専用鍵の使用: セキュリティ向上のため ### セキュリティ強化設定Host claude-remote
HostName your-remote-server.com
User your-username
IdentityFile ~/.ssh/claude_code_key
IdentitiesOnly yes
ServerAliveInterval 60
ServerAliveCountMax 3
StrictHostKeyChecking yes
PasswordAuthentication no
次のステップ¶
- Claude Code Docker環境構築ガイドでコンテナ開発環境を整備
- Claude Code Hooks設定で自動化ワークフローを構築