# 1Password SSHエージェントの高度な応用

### **1Password SSHエージェントの高度な応用** <a href="#usi54c68b4cu" id="usi54c68b4cu"></a>

### **段階的な移行** <a href="#lo892kx4qpeu" id="lo892kx4qpeu"></a>

#### **MacとLinuxの場合** <a href="#xo0npd5it16q" id="xo0npd5it16q"></a>

1Password SSHエージェントを全てのホストにすぐに使用しない場合は、使う必要はありません。1Password SSHエージェントは、OpenSSHエージェントなどの別のSSHエージェントと並行して実行できます。

SSHクライアント設定ファイル（\~/.ssh/config）を使うと、ホストごとに異なる認証詳細を提供できます。まずは 1 台または 2 台のホストで 1Password SSHエージェントを試し、準備ができたら残りのホストに徐々に移行することができます。

\~/.ssh/configファイルの例をいくつか示します。

例1

\# A host that uses the 1Password agent

Host raspberry-pi

HostName 192.168.12.34

User pi

IdentityAgent \~/.1password/agent.sock

\# A host that uses a local private key file that isn't saved in 1Password

Host ec2-server

HostName 54.123.45.67

User ec2-user

IdentityFile \~/.ssh/ssh-key-not-on-1password.pem

例2

\# By default, use the 1Password SSHagent for all hosts

Host \*

IdentityAgent \~/.1password/agent.sock

\# A host that uses a local private key file that isn't saved in 1Password

Host ec2-server

HostName 54.123.45.67

User ec2-user

IdentityFile \~/.ssh/ssh-key-not-on-1password.pem

IdentityAgent none

例3

\# By default, use a local private key file that's not saved in 1Password

Host \*

IdentityFile \~/.ssh/ssh-key-not-on-1password.pem

\# Use the 1Password agent on a single host instead of the local key file

Host raspberry-pi

HostName 192.168.12.34

User pi

IdentityAgent \~/.1password/agent.sock

IdentityFile none

#### **Windows** <a href="#ci2n13x9njbe" id="ci2n13x9njbe"></a>

Windowsでは、Microsoft OpenSSHが固定パイプ（\\\\.\pipe\openssh-ssh-agent）をリッスンするため、macOSやLinux ほど\~/.ssh/configファイルの柔軟性がありません。Windowsで1Password SSHエージェントを使う場合は、全てのホストに対して認証を許可する必要があります。

### **SSHサーバーの鍵の試行は6回までという制限** <a href="#b6tylgn2ez5i" id="b6tylgn2ez5i"></a>

SSHエージェントはSSHクライアントと連携して、エージェントが管理する全ての公開鍵を試し、サーバーが有効な鍵を認識するまで、それらの公開鍵を1つずつSSHサーバーに提供します。ただし、OpenSSHサーバーは、デフォルトで、着信SSH接続（MaxAuthTries） に対する認証試行回数を**6回**に制限するように設定されています。

SSHクライアントがSSHサーバーに7番目のキ鍵を提供すると、サーバーは接続を拒否し、SSHクライアントに次のエラー メッセージが表示されます。

Too many authentication failures

サーバー管理者は[サーバーの/etc/ssh/sshd\_config](https://linux.die.net/man/5/sshd_config)の中でMaxAuthTriesを設定することで制限を増やす*ことができます*が、これを変更できない（または望まない）ことが多いです。

#### **鍵をホストに一致させる** <a href="#id-1x24capa1wu0" id="id-1x24capa1wu0"></a>

代わりに、次の操Createを実行して、どのホストをどのSSH鍵に一致させるかを指定できます。

1. 1Password アプリで、SSHアイテムの「Public key」フィールドにあるDownloadボタンをクリックします。
2. \~/.ssh/configファイルに、接続先のホストのエントリーを追加し、IdentityFileに、ダウンロードした公開鍵のパスを設定します。秘密鍵は 1Passwordに残しておくことができます。

Host github.com\
IdentityFile \~/.ssh/public-key-downloaded-from-1password.pub\
IdentitiesOnly yes

これで、SSHクライアントはSSHサーバーに接続するときにどの鍵を使うかを認識するので、これらの認証制限に遭遇することはなくなります。

注意

一部のSSHクライアントは、IdentityFileでの公開鍵の指定をサポートしていません。[SSHクライアントの互換性](https://developer.1password.com/docs/ssh/agent/compatibility/)を参照してください。

#### **SSHエージェント設定ファイル** <a href="#lxtfeg5pytlv" id="lxtfeg5pytlv"></a>

[オプションのSSHエージェント設定ファイル](https://developer.1password.com/docs/ssh/agent/config/)（\~/.config/1Password/ssh/agent.toml ）をCreateすることもできます。エージェント設定ファイルを使うと、SSHエージェントがSSHサーバーに提供できる鍵と、それらの鍵をサーバーに提供する順序を指定できます。SSHエージェント設定ファイルをSSHクライアント設定ファイル（\~/.ssh/config） と一緒に使うと、認証制限をさらに回避できます。

### **複数のGitHubアカウントを使う場合** <a href="#kcfhd059tnuk" id="kcfhd059tnuk"></a>

全てのGitHubアカウントは、gitユーザーを使用してSSH経由で認証されます。仕事用アカウントと個人用アカウントなど、複数のGitHubアカウントを使うには、各リポジトリがー使うSSH鍵を設定する必要があります。![公開鍵をダウンロードする](https://4200399111-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8GVOyHz3wUSpdV3qlPwR%2Fuploads%2FpvHiyjg9X0gIvpqbvSY2%2F0.png?alt=media)

1. 1Passwordアプリで、SSH鍵アイテムを見つけます。
2. 「Public key」フィールドの［Download］ボタンをクリックします。使用している他のSSH鍵についても、この手順を繰り返します。
3. ダウンロードした公開鍵を\~/.ssh/ディレクトリーに移動します。
4. 個人用および仕事用のGitHubプロファイルのホストを設定するには、次の内容を\~/.ssh/configに追加します。

\# Personal GitHub

Host personalgit

HostName github.com

User git

IdentityFile \~/.ssh/personal\_git.pub

IdentitiesOnly yes

\# Work GitHub

Host workgit

HostName github.com

User git

IdentityFile \~/.ssh/work\_git.pub

IdentitiesOnly yes

1. 各リポジトリーについて、git URLを変更して、次の代わりに新しいホストのいずれかを使用します。

git remote set-url origin \<host>:\<workplace>/\<repo>.git

例：\
git remote set-url origin personalgit:1password/1password-teams-open-source.git

これで、SSHクライアントは各リポジトリーに使うSSH鍵を認識するようになります。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.dxable.com/1password/advanced-use-cases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
