Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
SSH 鍵のソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
SSH 鍵
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
[[Category:Secure Shell]] [[en:SSH keys]] [[es:SSH keys]] [[it:SSH keys]] [[ru:SSH keys]] [[sr:SSH keys]] [[tr:SSH_Anahtarları]] [[zh-CN:SSH keys]] SSH 鍵は[[Wikipedia:ja:公開鍵暗号|公開鍵暗号]]と[[Wikipedia:Challenge-response authentication|チャレンジ/レスポンス認証]]を使って SSH サーバーに自身を確認させる手段として用います。伝統的なパスワード認証と比べてこの方法を使用する利点として、ネットワークを介してパスワードを送信しなくてもサーバーから認証を受けられるということが挙げられます。パスワードを転送しているわけではないので、たとえ接続を盗聴されてもパスワードを盗まれたりクラックされる恐れがありません。さらに、SSH 鍵を使って認証をすることによって、ブルートフォース攻撃を受けるリスクを事実上なくすことができます。攻撃者が正しい証明書を得られる確率は劇的に減るからです。 セキュリティの向上につながるという他に、SSH 鍵認証は伝統的なパスワード認証よりも便利だという点もあります。SSH エージェントというプログラムを使うことで、システムごとのパスワードを記録して入力する必要はなくなり、SSH 鍵でサーバーに接続することが可能になります。 SSH 鍵に全く欠点がないというわけではなく、環境によっては相応しくないという場合もありますが、大抵の場合は SSH 鍵を使用することには強力なメリットが望めます。SSH 鍵の動作方法を理解することは、いつ、どのように鍵を使えば要求を満たせるのか考える手がかりになるでしょう。この記事では [[Secure Shell]] プロトコルについての基本的な知識を持っていて、[[公式リポジトリ]]の {{Pkg|openssh}} パッケージを既にインストールしていることを前提としています。 ==予備知識== SSH 鍵は常にペアで存在します。公開鍵と秘密鍵です。秘密鍵はあなたしか知らない鍵で、安全に保管する必要があります。逆に、公開鍵は接続したい SSH サーバーと自由に共有できます。 ファイル形式の公開鍵が SSH サーバーに存在し、あなたが接続をリクエストしたことを確認したら、SSH サーバーは公開鍵を使ってチャレンジをあなたに作成・送信します。このチャレンジは暗号文のようなもので、適切なレスポンスを返すことによって、アクセス権がサーバーから与えられます。暗号文を解読できるのは秘密鍵を持っている人だけということが、暗号文を特に安全なものにしています。公開鍵を使ってメッセージを暗号化することはできる一方で、公開鍵を使ってメッセージを復号化することはできません。秘密鍵を持っている、あなただけが、チャレンジを解読して適切なレスポンスを作成することができるわけです。 このチャレンジ/レスポンス認証は水面下で行われ、ユーザーが関知するところではありません。秘密鍵を持ってさえいれば (通常は {{ic|~/.ssh/}} ディレクトリに鍵が保存されます)、SSH クライアントはサーバーに適切なレスポンスを返すことが可能です。 秘密鍵は機密情報として考えてよく、暗号化されてディスクに保存されることもよくあります。この場合、秘密鍵が必要になったとき、最初にパスフレーズを入力して秘密鍵を復号化する必要があります。表面的には、SSH サーバーにログインパスワードを入力するのと変わりないように見えますが、実際にはローカルシステム上の秘密鍵を復号化するためのパスフレーズです。このパスフレーズはネットワークを介して送信されることはありませんし、送信するなんて言語道断です。 ==SSH 鍵のペアを生成== SSH 鍵のペアは {{ic|ssh-keygen}} コマンドを実行することで生成できます: {{hc |$ ssh-keygen -t rsa -b 4096 -C "$(whoami)@$(hostname)-$(date -I)" |<nowiki>Generating public/private rsa key pair. Enter file in which to save the key (/home/username/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/username/.ssh/id_rsa. Your public key has been saved in /home/username/.ssh/id_rsa.pub. The key fingerprint is: dd:15:ee:24:20:14:11:01:b8:72:a2:0f:99:4c:79:7f username@localhost-2014-11-22 The key's randomart image is: +--[RSA 4096]---+ | ..oB=. . | | . . . . . | | . . . + | | oo.o . . = | |o+.+. S . . . | |=. . E | | o . | | . | | | +-----------------+</nowiki>}} 上記の例では、{{ic|ssh-keygen}} は4096ビット長 ({{ic|-b 4096}}) の公開/秘密 RSA ({{ic|-t rsa}}) 鍵のペアを作成しています。拡張コメントにデータが含まれています ({{ic|-C "$(whoami)@$(hostname)-$(date -I)"}})。OpenSSH 5.1 から [http://www.cs.berkeley.edu/~dawnsong/papers/randomart.pdf ランダムな画像イメージ] が表示されるようになっており、鍵の指紋を視覚的に表しています。 ===暗号化のタイプを選択=== エドワーズ曲線デジタル署名アルゴリズム (ECDSA) は小さな鍵長で高速な操作を実現します、セキュリティについては昔の方法と変わりありません。ECDSA は OpenSSH 5.7 で導入され、認証用の推奨アルゴリズムとされています。[http://www.openssh.com/txt/release-5.7 OpenSSH 5.7 のリリースノート] を参照。'''ECDSA 鍵は旧バージョンの OpenSSH を使っているシステムと互換性がない場合があります。'''また、特許の問題を考慮して、メーカーによっては必要な実装が無効化されていることがあります。 {{Warning|There is [http://safecurves.cr.yp.to/rigid.html reason to be suspicious] of the NIST curves used to generate ECDSA keys. Depending on the threat model, it might be advisable to use Ed25519 or RSA.}} {{Note|2013年12月28日現在、Windows の SSH クライアントである PuTTY は ECDSA をサポートしておらず、ECDSA 鍵を使用しているサーバーに接続することができません。}} {{Note|1=2014年6月10日現在、ECDSA 鍵は GNOME Keyring で使用できません。[https://bugzilla.gnome.org/show_bug.cgi?id=641082 GNOME の既知のバグ] のためです。}} OpenSSH 6.5 から Ed25519 鍵がサポートされています: "Ed25519 は楕円曲線による署名方式で、ECDSA や DSA よりも安全なセキュリティ、高いパフォーマンスを実現します" [http://www.openssh.com/txt/release-6.5]。Ed25519 鍵は {{ic|ssh-keygen -t ed25519}} で生成できます。鍵長を設定する必要はありません。全ての Ed25519 鍵は256ビットです。 RSA (2048-16384ビット) または DSA (2048ビット) の鍵対を作成する場合、{{ic|ssh-keygen}} コマンドで {{ic|-t rsa}} または {{ic|-t dsa}} スイッチを使用して、忘れずに鍵長を増やして下さい。{{ic|-b}} スイッチを書かずに {{ic|ssh-keygen}} を実行することで作成されるデフォルトの鍵長で問題ありません。 {{Note|鍵が使用されるのは認証を行うときだけです。強固な鍵にすることで、SSH によってデータを送信する際の CPU の負担が増えることはありません。}} ===鍵の場所とパスフレーズを選択=== {{ic|ssh-keygen}} コマンドの実行時に、秘密鍵の名前と保存場所について尋ねられます。デフォルトでは、鍵は {{ic|~/.ssh/}} ディレクトリに保存され、名前は使用する暗号化のタイプに合わせて付けられます。この記事に出てくるサンプルコードをそのまま使用できるようにするため、デフォルトの名前と場所を使うことを推奨します。 パスフレーズを求められたときは、推測されにくいパスフレーズを入力してください。一般的に、長くてランダムなパスワードの方が強固でクラックされにくいパスワードであり、破れれることは少なくなります。 パスフレーズを設定しないで秘密鍵を作成することも可能です。パスフレーズが不要なことは便利である一方、リスクも伴うということを理解してください。パスフレーズを設定しなかった場合、秘密鍵はディスク上に平文で保存されることになります。秘密鍵ファイルにアクセスすることさえできれば、誰でも (鍵を使って認証を行っている) SSH サーバーの認証を掻い潜ることができてしまいます。さらに、パスフレーズを設定しないということは、root ユーザーを無条件で信頼することになります。root ユーザーはファイルのパーミッションを回避していつでも秘密鍵ファイルにアクセスすることができます。 ====鍵を変更せずに秘密鍵のパスフレーズを変更する==== 最初に作成した SSH 鍵のパスフレーズがあまりよろしくなくて変更しなくてはならない場合、{{ic|ssh-keygen}} コマンドを使うことで、実際の鍵を変更することなくパスフレーズだけ変更することができます。 RSA 秘密鍵のパスフレーズを変更するには、次を実行: $ ssh-keygen -f ~/.ssh/id_rsa -p ====複数の鍵の管理==== {{ic|~/.ssh/config}} ファイルを作成してホスト毎に認証に必要な鍵を指定することでホストごとに鍵を管理することができます。これは必須ではありません、ホスト全てに同じ鍵を使うこともできるからです。クライアント全てに同一の鍵を使いたくない場合は、以下のようにファイルを作成してください: Host SERVERNAME1 IdentitiesOnly yes IdentityFile ~/.ssh/id_rsa_SERVER1 # CheckHostIP yes # Port 22 Host SERVERNAME2 IdentitiesOnly yes IdentityFile ~/.ssh/id_rsa_SERVER2 # CheckHostIP no # Port 2177 ControlMaster auto ControlPath /tmp/%r@%h:%p 他のオプションについては次のコマンドで調べられます: $ man ssh_config 5 ==リモートサーバーに公開鍵をコピー== 鍵対を生成したら、公開鍵をリモートサーバーにコピーして、SSH 鍵認証が使えるようにする必要があります。公開鍵のファイル名は秘密鍵のファイル名に {{ic|.pub}} 拡張子を付けたものになります。秘密鍵は共有せず、ローカルマシンに残しておくようにしてください。 ===シンプルな方法=== {{Note|1=この方法はリモートサーバーが {{ic|sh}} 以外のシェル ({{ic|tcsh}} など) をデフォルトで使っている場合、失敗します。[https://bugzilla.redhat.com/show_bug.cgi?id=1045191 このバグレポート] を参照。}} 鍵のファイルが {{ic|~/.ssh/id_rsa.pub}} の場合、次のコマンドを実行します。 $ ssh-copy-id remote-server.org リモートマシンでユーザー名が異なる場合、サーバーの名前の前に {{ic|@}} とユーザー名を書きます。 $ ssh-copy-id username@remote-server.org 公開鍵のファイル名がデフォルトの {{ic|~/.ssh/id_rsa.pub}} ではない場合、{{ic|/usr/bin/ssh-copy-id: ERROR: No identities found}} というエラーが表示されます。その場合、公開鍵の場所を明示してください。 $ ssh-copy-id -i ~/.ssh/id_ecdsa.pub username@remote-server.org ssh サーバーがデフォルトの22番ポート以外を使っている場合、ポート番号を付して下さい。 $ ssh-copy-id -i ~/.ssh/id_ecdsa.pub -p 221 username@remote-server.org ===伝統的な方法=== デフォルトで、OpenSSH では、公開鍵は {{ic|~/.ssh/authorized_keys}} と連結する必要があります。まず公開鍵をリモートサーバーにコピーしてください。 $ scp ~/.ssh/id_ecdsa.pub username@remote-server.org: 上記の例では {{ic|scp}} によって公開鍵 ({{ic|id_ecdsa.pub}}) をリモートサーバーのホームディレクトリにコピーしています。サーバーアドレスの最後にはかならず {{ic|:}} を付けるのを忘れないで下さい。また、必要に応じて上記の例にある公開鍵の名前は置き換えるようにしてください。 リモートサーバー側では、(ディレクトリが存在しない場合) {{ic|~/.ssh}} ディレクトリを作成して {{ic|authorized_keys}} ファイルに公開鍵を追記する必要があります。 $ ssh username@remote-server.org username@remote-server.org's password: $ mkdir ~/.ssh $ chmod 700 ~/.ssh $ cat ~/id_ecdsa.pub >> ~/.ssh/authorized_keys $ rm ~/id_ecdsa.pub $ chmod 600 ~/.ssh/authorized_keys 最後の2つのコマンドではサーバーから公開鍵ファイルを削除して、{{ic|authorized_keys}} ファイルにパーミッションを設定して、所有者である貴方以外のユーザーが読み書きできないようにしています。 ==セキュリティ== ===authorized_keys ファイルの保全=== さらなる保護のため、ユーザーが新しい公開鍵を追加して接続することを禁止させることができます。 {{ic|authorized_keys}} ファイルをユーザーからの読み取り専用にして他のパーミッションを全て拒否してください: $ chmod 400 ~/.ssh/authorized_keys ユーザーがパーミッションを戻せないように、{{ic|authorized_keys}} ファイルに [[ファイルのパーミッションと属性#chattr と lsattr|immutable ビットを設定]]してください。これだけだとユーザーが {{ic|~/.ssh}} ディレクトリの名前を変更して新しい {{ic|~/.ssh}} ディレクトリと {{ic|authorized_keys}} ファイルを作成してしまう可能性があります。{{ic|~/.ssh}} ディレクトリにも immutable ビットを設定するようにしてください。 {{Note|新しい鍵を追加する必要が出たら、一度 {{ic|authorized_keys}} の immutable ビットを削除して書き込み可能にする必要があります。鍵を追加したらまたビットを設定してください。}} ===パスワードログインの無効化=== 公開鍵をリモートの SSH サーバーにコピーすることで、ネットワークを介してパスワードを入力する必要はなくなりましたが、これだけではパスワードの総当り攻撃に対しては防御になっていません。秘密鍵が使用されなかった場合、SSH サーバーはデフォルトでパスワード認証を行うようになっています。パスワードを推測することによって攻撃者がアクセスを取得しようとする恐れがあります。パスワードログインを無効化するには、リモートサーバーの {{ic|/etc/ssh/sshd_config}} ファイル内の以下の行を編集してください。 {{hc|/etc/ssh/sshd_config| PasswordAuthentication no ChallengeResponseAuthentication no}} === 2段階認証と公開鍵 === OpenSSH 6.2 から、{{ic|AuthenticationMethods}} オプションを使って自分でチェインを追加して認証することができるようになりました。これによって公開鍵だけでなく2段階認証が使うことができます。 Google Authenticator のセットアップについては [[Google Authenticator]] を見て下さい。 OpenSSH で PAM を使うには、以下のファイルを編集します: {{hc|/etc/ssh/sshd_config| ChallengeResponseAuthentication yes AuthenticationMethods publickey keyboard-interactive:pam }} これで公開鍵かユーザー認証のどちらかでログインできます。 公開鍵とユーザー認証の両方を使って認証したい場合、AuthenticationMethods でスペースの代わりにカンマを使って下さい: {{hc|/etc/ssh/sshd_config| ChallengeResponseAuthentication yes AuthenticationMethods publickey,keyboard-interactive:pam }} ==SSH エージェント== 秘密鍵をパスフレーズで暗号化した場合、公開鍵認証を使って SSH サーバーに接続するたびに設定したパスフレーズを入力する必要があります。認証を進める前に秘密鍵を復号化するために {{ic|ssh}} や {{ic|scp}} が呼ばれるたびにパスフレーズが求められるのです。 SSH エージェントは復号化された秘密鍵をキャッシュして、あなたに代わって SSH クライアントプログラムに鍵を提出します。この場合、パスフレーズを入力するのは一度だけでよく、その時に秘密鍵がエージェントのキャッシュに追加されます。これは頻繁に SSH 接続を行う場合にとても便利です。 大抵、エージェントはログイン時に自動的に実行されるように設定され、ログインセッションの間はずっと実行し続けます。この効果を得るのに様々なエージェント、フロントエンド、設定が存在します。このセクションでは様々なソリューションを並べているので、必要に応じて選びとるようにしてください。 ===ssh-agent=== ssh-agent は OpenSSH に含まれているデフォルトのエージェントです。直接使用することもできますし、後のセクションで触れている、フロントエンドのためのバックエンドとして使うこともできます。{{ic|ssh-agent}} が実行されると、ssh-agent は自分をバックグラウンドにフォークして、使用する環境変数を出力します。 {{hc|$ ssh-agent|2= SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK; SSH_AGENT_PID=2148; export SSH_AGENT_PID; echo Agent pid 2148; }} これらの変数を利用するには、{{ic|eval}} コマンドを通してコマンドを実行してください。 {{hc|$ eval $(ssh-agent)| Agent pid 2157 }} {{Tip|上記のコマンドを {{ic|~/.bash_profile}} スクリプトに追加すればログインシェルが起動した時に自動で実行されます。}} {{ic|ssh-agent}} を実行したら、秘密鍵をキャッシュに追加する必要があります: {{hc|$ ssh-add ~/.ssh/id_ecdsa| Enter passphrase for /home/user/.ssh/id_ecdsa: Identity added: /home/user/.ssh/id_ecdsa (/home/user/.ssh/id_ecdsa) }} 秘密鍵が暗号化されている場合、{{ic|ssh-add}} はパスフレーズを入力するように要求します。秘密鍵がエージェントに追加されたら、パスフレーズを入力することなく SSH 接続を行うことができるようになります。 鍵が必要になるまでパスフレーズの入力をしないようにするには、以下を {{ic|~/.bashrc}} に追加します: <nowiki>if ! pgrep -u $USER ssh-agent > /dev/null; then ssh-agent > ~/.ssh-agent-thing fi if [[ "$SSH_AGENT_PID" == "" ]]; then eval $(<~/.ssh-agent-thing) fi ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh'</nowiki> {{ic|ssh-agent}} プロセスが存在しない場合にプロセスが実行され、出力が保存されます。プロセスが既に存在する場合、キャッシュされた {{ic|ssh-agent}} の出力を取得して必要な環境変数を設定します。また、必要なときは、{{ic|ssh}} にエイリアスを作成してエージェントに鍵を追加し、それからエイリアスを削除します。この方法の欠点は {{ic|git}} など、{{ic|ssh}} 以外の秘密鍵を使用するコマンドでは鍵は追加されないということです。 後で述べるように、この問題を回避できる {{ic|ssh-agent}} のフロントエンドや代替エージェントも多数存在します。 ====systemd ユーザーで ssh-agent を起動==== [[systemd/ユーザー]]機能を使ってエージェントを起動することができます。{{ic|~/.config/systemd/user}} フォルダに以下のユニットファイルを配置してください: {{hc|~/.config/systemd/user/ssh-agent.service|<nowiki> [Unit] Description=SSH key agent [Service] Type=forking Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket ExecStart=/usr/bin/ssh-agent -a $SSH_AUTH_SOCK [Install] WantedBy=</nowiki>''default''.target }} {{ic|1=export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"}} をシェルのスタートアップファイルに追加してください。例えば [[Bash]] の場合 {{ic|.bash_profile}} です。その後、サービスを有効化・起動してください。 ====ssh-agent をラッパープログラムとして使う==== ssh-agent を (X セッションごとに) 起動する別の方法は [http://upc.lbl.gov/docs/user/sshagent.shtml UC Berkeley Labs による ssh-agent チュートリアル] に載っています。{{ic|startx}} コマンドで X を起動する場合に、以下のように {{ic|ssh-agent}} を {{ic|startx}} の前に付けることができます: $ ssh-agent startx And so you don't even need to think about it you can put an alias in your {{ic|.bash_aliases}} file or equivalent: alias startx='ssh-agent startx' Doing it this way avoids the problem of having extraneous {{ic|ssh-agent}} instances floating around between login sessions. Exactly one instance will live and die with the entire X session. {{note|You can also add {{ic|eval $(ssh-agent)}} to {{ic|~/.xinitrc}}.}} See [[#ssh-add で x11-ssh-askpass を呼び出す|the below notes on using x11-ssh-askpass with ssh-add]] for an idea on how to immediately add your key to the agent. ===GnuPG エージェント=== [[公式リポジトリ]] の {{Pkg|gnupg}} パッケージに入っている [[GnuPG]] エージェントには OpenSSH エージェントのエミュレーションがあります。GnuPG スイートを既に使っている場合は、GnuPG エージェントを使って SSH 鍵をキャッシュすることが可能です。さらに、場合によっては GnuPG エージェントがパスフレーズ管理の一部として提供している PIN エントリダイアログを使うのも良いでしょう。 {{Note|KDE を使っていて {{Pkg|kde-agent}} をインストールしている場合、{{ic|enable-ssh-support}} を {{ic|~/.gnupg/gpg-agent.conf}} に設定するだけで設定は完了です。KDE を使っていない場合は、さらに先まで読んで下さい。}} SSH 鍵を GnuPG エージェントで使うには、{{ic|~/.gnupg/gpg-agent.conf}} ファイルで {{ic|enable-ssh-support}} を有効にする必要があります。 {{hc|~/.gnupg/gpg-agent.conf| # Enable SSH support enable-ssh-support }} 次に、{{ic|gpg-connect-agent}} を使っている場合は ''gpg-agent'' を起動して、{{ic|SSH_AUTH_SOCK}} を設定することで SSH が ''ssh-agent'' ではなく ''gpg-agent'' を使うようにします。そして GPG TTY を設定して X セッションにユーザーが切り替わった場合は TTY を更新します。例: {{hc|~/.bashrc|<nowiki> #!/bin/sh # Start the gpg-agent if not already running if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then gpg-connect-agent /bye >/dev/null 2>&1 fi # Set SSH to use gpg-agent unset SSH_AGENT_PID if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then export SSH_AUTH_SOCK="${HOME}/.gnupg/S.gpg-agent.ssh" fi # Set GPG TTY GPG_TTY=$(tty) export GPG_TTY # Refresh gpg-agent tty in case user switches into an X session gpg-connect-agent updatestartuptty /bye >/dev/null </nowiki>}} Once ''gpg-agent'' is running you can use ''ssh-add'' to approve keys, just like you did with plain ''ssh-agent''. The list of approved keys is stored in the {{ic|~/.gnupg/sshcontrol}} file. Once your key is approved, you will get a PIN entry dialog every time your passphrase is needed. You can control passphrase caching in the {{ic|~/.gnupg/gpg-agent.conf}} file. The following example would have ''gpg-agent'' cache your keys for 3 hours: {{hc|~/.gnupg/gpg-agent.conf| # Cache settings default-cache-ttl 10800 default-cache-ttl-ssh 10800 }} Other useful settings for this file include the PIN entry program (GTK, QT, or ncurses version), keyboard grabbing, and so on... {{hc|~/.gnupg/gpg-agent.conf|<nowiki> # Keyboard control #no-grab # PIN entry program #pinentry-program /usr/bin/pinentry-curses #pinentry-program /usr/bin/pinentry-qt4 #pinentry-program /usr/bin/pinentry-kwallet #pinentry-program /usr/bin/pinentry-gtk-2 </nowiki>}} ===Keychain=== [http://www.funtoo.org/Keychain Keychain] は出来る限りユーザーの手を煩わせることなく SSH 鍵の管理を楽にするために作られたプログラムです。''ssh-agent'' と ''ssh-add'' の両方を動かすシェルスクリプトとして実装されています。Keychain の特徴として、複数のログインセッションで単一の ''ssh-agent'' プロセスを維持することができます。したがって、パスフレーズを入力するのはマシンを起動したときだけで済みます。 [[公式リポジトリ]]から {{Pkg|keychain}} パッケージを[[インストール]]してください。 以下の行を {{ic|~/.bash_profile}} に追記: {{hc|~/.bash_profile| eval $(keychain --eval --agents ssh -Q --quiet id_ecdsa) }} In the above example, the {{ic|--eval}} switch outputs lines to be evaluated by the opening {{ic|eval}} command. This sets the necessary environments variables for SSH client to be able to find your agent. The {{ic|--agents}} switch is not strictly necessary because Keychain will build the list automatically based on the existence of ''ssh-agent'' or ''gpg-agent'' on the system. Adding the {{ic|--quiet}} switch will limit output to warnings, errors, and user prompts. If you want greater security, replace {{ic|-Q}} with {{ic|--clear}} but will be less convenient. If necessary, replace {{ic|~/.ssh/id_ecdsa}} with the path to your private key. For those using a non-Bash compatible shell, see {{ic|keychain --help}} or {{ic|man keychain}} for details on other shells. To test Keychain, log out from your session and log back in. If this is your first time running Keychain, it will prompt you for the passphrase of the specified private key. Because Keychain reuses the same ''ssh-agent'' process on successive logins, you should not have to enter your passphrase the next time you log in. You will only be prompted for your passphrase once each time the machine is rebooted. ===envoy=== [https://github.com/vodik/envoy envoy] は Keychain の代替プログラムです。Envoy は[[公式リポジトリ]]の {{Pkg|envoy}} でインストールできます。また、Git バージョンは [[AUR]] の {{AUR|envoy-git}} でインストールできます。 インストールしたら、{{ic|envoy@ssh-agent.socket}} を[[有効化]]して envoy ソケットをセットアップしてください。 And add to your shell's rc file: envoy -t ssh-agent -a ''ssh_key'' source <(envoy -p) If the key is {{ic|~/.ssh/id_rsa}}, {{ic|~/.ssh/id_dsa}}, {{ic|~/.ssh/id_ecdsa}}, or {{ic|~/.ssh/identity}}, the {{ic|-a ''ssh_key''}} parameter is not needed. ====envoy で kwallet に キーパスフレーズを保存==== SSH 鍵に長いパスワードを設定している場合、思い出すのが一苦労かもしれません。そんなときは kwallet にパスワードを保存しましょう。{{Pkg|envoy}} だけでなく、[[公式リポジトリ]]から {{Pkg|ksshaskpass}} と {{Pkg|ksshaskpass}} をインストールしてください。そして、systemd で envoy ソケットを有効化してください (上を参照)。 {{Note|As of April 30, 2015, if after installation {{Pkg|ksshaskpass}} keeps asking for access to your wallet even after having submitted the password, you might have [[https://bbs.archlinux.org/viewtopic.php?id=192862 this]] problem. The proposed solution is to install {{Aur|ksshaskpass4}}, though this might break your login.}} まず、以下のスクリプトを {{ic|~/.kde4/Autostart/ssh-agent.sh}} に追加: #!/bin/sh envoy -t ssh-agent -a ''ssh_key'' それから、次のコマンドを実行してスクリプトに実行可能属性を付与: {{ic|chmod +x ~/.kde4/Autostart/ssh-agent.sh}} そして以下を {{ic|~/.kde4/env/ssh-agent.sh}} に追加: #!/bin/sh eval $(envoy -p) KDE にログインしたときに、{{ic|ssh-agent.sh}} スクリプトが実行されるようになります。このスクリプトは ''ksshaskpass'' を呼び出して、envoy が ''ssh-agent'' を呼び出したときに kwallet パスワードの入力を求めます。 ===x11-ssh-askpass=== The {{pkg|x11-ssh-askpass}} package provides a graphical dialog for entering your passhrase when running an X session. ''x11-ssh-askpass'' depends only on the {{Pkg|libx11}} and {{Pkg|libxt}} libraries, and the appearance of ''x11-ssh-askpass'' is customizable. While it can be invoked by the ''ssh-add'' program, which will then load your decrypted keys into [[#ssh-agent|ssh-agent]], the following instructions will, instead, configure ''x11-ssh-askpass'' to be invoked by the aforementioned [[#Keychain|Keychain]] script. {{Pkg|keychain}} と {{Pkg|x11-ssh-askpass}} をインストールしてください。どちらも[[公式リポジトリ]]に入っています。 Edit your {{ic|~/.xinitrc}} file to include the following lines, replacing the name and location of your private key if necessary. Be sure to place these commands '''before''' the line which invokes your window manager. {{hc|~/.xinitrc| keychain ~/.ssh/id_ecdsa [ -f ~/.keychain/$HOSTNAME-sh ] && . ~/.keychain/$HOSTNAME-sh 2>/dev/null [ -f ~/.keychain/$HOSTNAME-sh-gpg ] && . ~/.keychain/$HOSTNAME-sh-gpg 2>/dev/null ... exec openbox-session}} In the above example, the first line invokes ''keychain'' and passes the name and location of your private key. If this is not the first time ''keychain'' was invoked, the following two lines load the contents of {{ic|$HOSTNAME-sh}} and {{ic|$HOSTNAME-sh-gpg}}, if they exist. These files store the environment variables of the previous instance of ''keychain''. ====ssh-add で x11-ssh-askpass を呼び出す==== The ''ssh-add'' manual page specifies that, in addition to needing the {{ic|DISPLAY}} variable defined, you also need {{ic|SSH_ASKPASS}} set to the name of your askpass program (in this case ''x11-ssh-askpass''). It bears keeping in mind that the default Arch Linux installation places the ''x11-ssh-askpass'' binary in {{ic|/usr/lib/ssh/}}, which will not be in most people's {{ic|PATH}}. This is a little annoying, not only when declaring the {{ic|SSH_ASKPASS}} variable, but also when theming. You have to specify the full path everywhere. Both inconveniences can be solved simultaneously by symlinking: $ ln -sv /usr/lib/ssh/x11-ssh-askpass ~/bin/ssh-askpass This is assuming that {{ic|~/bin}} is in your {{ic|PATH}}. So now in your {{ic|.xinitrc}}, before calling your window manager, one just needs to export the {{ic|SSH_ASKPASS}} environment variable: $ export SSH_ASKPASS=ssh-askpass and your [[X resources]] will contain something like: ssh-askpass*background: #000000 Doing it this way works well with [[#ssh-agent をラッパープログラムとして使う|the above method on using ''ssh-agent'' as a wrapper program]]. You start X with {{ic|ssh-agent startx}} and then add ''ssh-add'' to your window manager's list of start-up programs. ====テーマ==== ''x11-ssh-askpass'' ダイアログの外観は [[X resources]] を設定することでカスタマイズできます。''x11-ssh-askpass'' の [http://www.jmknoble.net/software/x11-ssh-askpass/ ホームページ] にはいくつか [http://www.jmknoble.net/software/x11-ssh-askpass/screenshots.html サンプルテーマ] が挙げられています。詳しくは ''x11-ssh-askpass'' のマニュアルページを見て下さい。 ====他のパスフレーズダイアログ==== ''x11-ssh-askpass'' の代わりに他のパスフレーズダイアログプログラムを使うこともできます: * {{Pkg|ksshaskpass}} は公式リポジトリからインストールできます。{{Pkg|kdelibs}} に依存しており [[KDE]] デスクトップ環境にうってつけです。 * {{Pkg|openssh-askpass}} は {{Pkg|qt4}} ライブラリに依存しており公式リポジトリからインストールできます。 ===pam_ssh=== [http://pam-ssh.sourceforge.net/ pam_ssh] プロジェクトは SSH 秘密鍵の [[Wikipedia:Pluggable authentication module|Pluggable Authentication Module]] (PAM) を提供しています。このモジュールを使うことで SSH 接続のシングルサインオンができます。ログイン時に、伝統的なシステムパスワードの代わりに、もしくはそれに加えて、SSH 秘密鍵のパスフレーズを入力することができます。認証が完了したら、pam_ssh モジュールは ssh-agent を生成して復号化された秘密鍵をセッションの間だけ保存します。 tty ログインプロンプトでシングルサインオンを有効にしたいときは、[[Arch User Repository]] から非公式の {{AUR|pam_ssh}} パッケージをインストールしてください。 {{Note|pam_ssh 2.0 では認証プロセスに使用する秘密鍵を {{ic|~/.ssh/login-keys.d/}} 下に配置する必要があります。}} 秘密鍵ファイルのシンボリックリンクを作成して {{ic|~/.ssh/login-keys.d/}} に配置します。以下の例の {{ic|id_rsa}} をあなたの秘密鍵ファイルの名前に置き換えて下さい: $ mkdir ~/.ssh/login-keys.d/ $ cd ~/.ssh/login-keys.d/ $ ln -s ../id_rsa {{ic|/etc/pam.d/login}} ファイルを編集して以下の例で太字でハイライトされているテキストを記述してください。これらの行の順番は重要で、ログインに影響します。 {{Warning|Misconfiguring PAM can leave the system in a state where all users become locked out. Before making any changes, you should have an understanding of how PAM configuration works as well as a backup means of accessing the PAM configuration files, such as an Arch Live CD, in case you become locked out and need to revert any changes. An IBM developerWorks [http://www.ibm.com/developerworks/linux/library/l-pam/index.html article] is available which explains PAM configuration in further detail.}} {{hc|/etc/pam.d/login|2= #%PAM-1.0 auth required pam_securetty.so auth requisite pam_nologin.so auth include system-local-login '''auth optional pam_ssh.so try_first_pass''' account include system-local-login session include system-local-login '''session optional pam_ssh.so''' }} In the above example, login authentication initially proceeds as it normally would, with the user being prompted to enter his user password. The additional {{ic|auth}} authentication rule added to the end of the authentication stack then instructs the pam_ssh module to try to decrypt any private keys found in the {{ic|~/.ssh/login-keys.d}} directory. The {{ic|try_first_pass}} option is passed to the pam_ssh module, instructing it to first try to decrypt any SSH private keys using the previously entered user password. If the user's private key passphrase and user password are the same, this should succeed and the user will not be prompted to enter the same password twice. In the case where the user's private key passphrase user password differ, the pam_ssh module will prompt the user to enter the SSH passphrase after the user password has been entered. The {{ic|optional}} control value ensures that users without an SSH private key are still able to log in. In this way, the use of pam_ssh will be transparent to users without an SSH private key. If you use another means of logging in, such as an X11 display manager like [[SLiM]] or [[XDM]] and you would like it to provide similar functionality, you must edit its associated PAM configuration file in a similar fashion. Packages providing support for PAM typically place a default configuration file in the {{ic|/etc/pam.d/}} directory. Further details on how to use pam_ssh and a list of its options can be found in the pam_ssh man page. ====pam_ssh の既知の問題==== Work on the pam_ssh project is infrequent and the documentation provided is sparse. You should be aware of some of its limitations which are not mentioned in the package itself. * Versions of pam_ssh prior to version 2.0 do not support SSH keys employing the newer option of ECDSA (elliptic curve) cryptography. If you are using earlier versions of pam_ssh you must use either RSA or DSA keys. * The {{ic|ssh-agent}} process spawned by pam_ssh does not persist between user logins. If you like to keep a [[GNU Screen]] session active between logins you may notice when reattaching to your screen session that it can no longer communicate with ssh-agent. This is because the GNU Screen environment and those of its children will still reference the instance of ssh-agent which existed when GNU Screen was invoked but was subsequently killed in a previous logout. The [[#Keychain|Keychain]] front-end avoids this problem by keeping the ssh-agent process alive between logins. ===GNOME Keyring=== [[GNOME]] デスクトップを使用する場合、[[GNOME Keyring]] ツールを SSH エージェントとして使うことができます。詳しくは [[GNOME Keyring]] の記事を見て下さい。 ===Kwallet を使って SSH 鍵を保存=== kwallet を使って SSH 鍵を保存する方法は、[[KDE Wallet#KDE ウォレットを使って ssh 鍵を保存]]を見て下さい。 ===KeePass2 と KeeAgent プラグイン=== [http://lechnology.com/software/keeagent/ KeeAgent] は [[KeePass]] のプラグインで、SSH 鍵を KeePass データベースに保存することができ、他のプログラムから SSH 認証に使用されます。 * PuTTY と OpenSSH の秘密鍵フォーマットをサポート。 * Linux/Mac のネイティブの SSH エージェントと Windows の PuTTY で動作。 [[KeePass#プラグインのインストール]]を見て、{{AUR|keepass-plugin-keeagent}} パッケージを[[インストール]]してください。 ==トラブルシューティング== If it appears that the SSH server is ignoring your keys, ensure that you have the proper permissions set on all relevant files.<br /> For the local machine: $ chmod 700 ~/ $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/id_ecdsa For the remote machine: $ chmod 700 ~/ $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys If that does not solve the problem you may try temporarily setting {{ic|StrictModes}} to {{ic|no}} in {{ic|sshd_config}}. If authentication with StrictModes off is successful, it is likely an issue with file permissions persists. {{Tip|Do not forget to set {{ic|StrictModes}} to {{ic|yes}} for added security.}} Make sure the remote machine supports the type of keys you are using. Try using RSA or DSA keys instead [[#Generating an SSH key pair]] Some servers do not support ECDSA keys. Failing this, run the sshd in debug mode and monitor the output while connecting: # /usr/bin/sshd -d === kdm を使う === KDM doesn't launch the ssh-agent process directly, {{Pkg|kde-agent}} used to start ssh-agent on login, but since version 20140102-1 it got [https://projects.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/kde-agent&id=1070467b0f74b2339ceca2b9471d1c4e2b9c9c8f removed]. In order to start ssh-agent on KDE startup for a user, create scripts to start ssh-agent on startup and one to kill it on logoff: {{bc|<nowiki> echo -e '#!/bin/sh\n[ -n "$SSH_AGENT_PID" ] || eval "$(ssh-agent -s)"' > ~/.kde4/env/ssh-agent-startup.sh echo -e '#!/bin/sh\n[ -z "$SSH_AGENT_PID" ] || eval "$(ssh-agent -k)"' > ~/.kde4/shutdown/ssh-agent-shutdown.sh chmod 755 ~/.kde4/env/ssh-agent-startup.sh ~/.kde4/shutdown/ssh-agent-shutdown.sh </nowiki>}} [[KDE#Plasma_5|Plasma 5]] を使用している場合、{{ic|~/.kde4}} ではなく {{ic|~/.config/plasma-workspace/}} ディレクトリにスクリプトを作成してください: {{bc|<nowiki> echo -e '#!/bin/sh\n[ -n "$SSH_AGENT_PID" ] || eval "$(ssh-agent -s)"' > ~/.config/plasma-workspace/env/ssh-agent-startup.sh echo -e '#!/bin/sh\n[ -z "$SSH_AGENT_PID" ] || eval "$(ssh-agent -k)"' > ~/.config/plasma-workspace/shutdown/ssh-agent-shutdown.sh chmod 755 ~/.config/plasma-workspace/env/ssh-agent-startup.sh ~/.config/plasma-workspace/shutdown/ssh-agent-shutdown.sh </nowiki>}} ==参照== * [http://www.ibm.com/developerworks/linux/library/l-keyc.html OpenSSH key management, Part 1] * [http://www.ibm.com/developerworks/linux/library/l-keyc2/ OpenSSH key management, Part 2] * [http://www.ibm.com/developerworks/library/l-keyc3/ OpenSSH key management, Part 3] * [http://kimmo.suominen.com/docs/ssh/ Getting started with SSH] * [http://www.openssh.com/txt/release-5.7 OpenSSH 5.7 Release Notes] * [https://stribika.github.io/2015/01/04/secure-secure-shell.html Secure Secure Shell]
このページで使用されているテンプレート:
テンプレート:AUR
(
ソースを閲覧
)
テンプレート:Broken package link
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:Man
(
ソースを閲覧
)
テンプレート:Note
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
テンプレート:Tip
(
ソースを閲覧
)
テンプレート:Warning
(
ソースを閲覧
)
SSH 鍵
に戻る。
検索
検索
SSH 鍵のソースを表示
話題を追加