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 keys always come in pairs, one private and the other public. The private key is known only to you and it should be safely guarded. By contrast, the public key can be shared freely with any SSH server to which you would like to connect. When an SSH server has your public key on file and sees you requesting a connection, it uses your public key to construct and send you a challenge. This challenge is like a coded message and it must be met with the appropriate response before the server will grant you access. What makes this coded message particularly secure is that it can only be understood by someone with the private key. While the public key can be used to encrypt the message, it cannot be used to decrypt that very same message. Only you, the holder of the private key, will be able to correctly understand the challenge and produce the correct response. This challenge-response phase happens behind the scenes and is invisible to the user. As long as you hold the private key, which is typically stored in the {{ic|~/.ssh/}} directory, your SSH client should be able to reply with the appropriate response to the server. Because private keys are considered sensitive information, they are often stored on disk in an encrypted form. In this case, when the private key is required, a passphrase must first be entered in order to decrypt it. While this might superficially appear the same as entering a login password on the SSH server, it is only used to decrypt the private key on the local system. This passphrase is not, and should not, be transmitted over the network. ==SSH 鍵のペアを生成== An SSH key pair can be generated by running the {{ic|ssh-keygen}} command: {{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>}} In the above example, {{ic|ssh-keygen}} generates a 4096 bit long ({{ic|-b 4096}}) public/private RSA ({{ic|-t rsa}}) key pair with an extended comment including the data ({{ic|-C "$(whoami)@$(hostname)-$(date -I)"}}). The [http://www.cs.berkeley.edu/~dawnsong/papers/randomart.pdf randomart image] was introduced in OpenSSH 5.1 as an easier means of visually identifying the key fingerprint. ===暗号化のタイプを選択=== The Elliptic Curve Digital Signature Algorithm (ECDSA) provides smaller key sizes and faster operations for equivalent estimated security to the previous methods. It was introduced as the preferred algorithm for authentication in OpenSSH 5.7, see [http://www.openssh.com/txt/release-5.7 OpenSSH 5.7 Release Notes]. '''ECDSA keys might not be compatible with systems that ship old versions of OpenSSH.''' Some vendors also disable the required implementations due to potential patent issues. {{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|As of December 28, 2013, the Windows SSH client PuTTY does not support ECDSA and cannot connect to a server that uses ECDSA keys.}} {{Note|1=As of June 10, 2014, ECDSA keys will not work with GNOME Keyring because of a known [https://bugzilla.gnome.org/show_bug.cgi?id=641082 GNOME bug].}} As of OpenSSH 6.5 Ed25519 keys are supported: "Ed25519 is a elliptic curve signature scheme that offers better security than ECDSA and DSA and good performance."[http://www.openssh.com/txt/release-6.5] They can be generated by {{ic|ssh-keygen -t ed25519}}. There is no need to set the key size, as all Ed25519 keys are 256 bits. If you choose to create an RSA (2048-16384 bit) or DSA (2048 bit) key pair instead, use the {{ic|-t rsa}} or {{ic|-t dsa}} switches in your {{ic|ssh-keygen}} command and do not forget to increase the key size. Running {{ic|ssh-keygen}} without the {{ic|-b}} switch should provide reasonable defaults. {{Note|These keys are used only to authenticate you; choosing stronger keys will not increase CPU load when transferring data over SSH.}} ===鍵の場所とパスフレーズを選択=== Upon issuing the {{ic|ssh-keygen}} command, you will be prompted for the desired name and location of your private key. By default, keys are stored in the {{ic|~/.ssh/}} directory and named according to the type of encryption used. You are advised to accept the default name and location in order for later code examples in this article to work properly. When prompted for a passphrase, choose something that will be hard to guess if you have the security of your private key in mind. A longer, more random password will generally be stronger and harder to crack should it fall into the wrong hands. It is also possible to create your private key without a passphrase. While this can be convenient, you need to be aware of the associated risks. Without a passphrase, your private key will be stored on disk in an unencrypted form. Anyone who gains access to your private key file will then be able to assume your identity on any SSH server to which you connect using key-based authentication. Furthermore, without a passphrase, you must also trust the root user, as he can bypass file permissions and will be able to access your unencrypted private key file at any time. ====鍵を変更せずに秘密鍵のパスフレーズを変更する==== If the originally chosen SSH key passphrase is undesirable or must be changed, one can use the {{ic|ssh-keygen}} command to change the passphrase without changing the actual key. To change the passphrase for the private RSA key, run the following command: $ ssh-keygen -f ~/.ssh/id_rsa -p ====複数の鍵の管理==== It's possible to manage keys per host by creating the file {{ic|~/.ssh/config}} and assigning each host another key for authentication if needed. Actually it's not needed, because you could use the same identity for each host. Yet, you don't want to use the same key for each client, then create this file like shown here: 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 Many more options you will find with $ man ssh_config 5 ==リモートサーバーに公開鍵をコピー== Once you have generated a key pair, you will need to copy the public key to the remote server so that it will use SSH key authentication. The public key file shares the same name as the private key except that it is appended with a {{ic|.pub}} extension. Note that the private key is not shared and remains on the local machine. ===シンプルな方法=== {{Note|1=This method might fail if the remote server uses a non-{{ic|sh}} shell such as {{ic|tcsh}} as default. See [https://bugzilla.redhat.com/show_bug.cgi?id=1045191 this bug report].}} If your key file is {{ic|~/.ssh/id_rsa.pub}} you can simply enter the following command. $ ssh-copy-id remote-server.org If your username differs on remote machine, be sure to prepend the username followed by {{ic|@}} to the server name. $ ssh-copy-id username@remote-server.org If your public key filename is anything other than the default of {{ic|~/.ssh/id_rsa.pub}} you will get an error stating {{ic|/usr/bin/ssh-copy-id: ERROR: No identities found}}. In this case, you must explicitly provide the location of the public key. $ ssh-copy-id -i ~/.ssh/id_ecdsa.pub username@remote-server.org If the ssh server is listening on a port other than default of 22, be sure to include it within the host argument. $ ssh-copy-id -i ~/.ssh/id_ecdsa.pub -p 221 username@remote-server.org ===伝統的な方法=== By default, for OpenSSH, the public key needs to be concatenated with {{ic|~/.ssh/authorized_keys}}. Begin by copying the public key to the remote server. $ scp ~/.ssh/id_ecdsa.pub username@remote-server.org: The above example copies the public key ({{ic|id_ecdsa.pub}}) to your home directory on the remote server via {{ic|scp}}. Do not forget to include the {{ic|:}} at the end of the server address. Also note that the name of your public key may differ from the example given. On the remote server, you will need to create the {{ic|~/.ssh}} directory if it does not yet exist and append your public key to the {{ic|authorized_keys}} file. $ 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 The last two commands remove the public key file from the server and set the permissions on the {{ic|authorized_keys}} file such that it is only readable and writable by you, the owner. ==セキュリティ== ===authorized_keys ファイルの保全=== For additional protection, you can prevent users from adding new public keys and connecting from them. Make the {{ic|authorized_keys}} file read-only for the user and deny all other permissions: $ chmod 400 ~/.ssh/authorized_keys To keep the user from simply changing the permissions back, [[File permissions and attributes#chattr and lsattr|set the immutable bit]] on the {{ic|authorized_keys}} file. After that the user could rename the {{ic|~/.ssh}} directory to something else and create a new {{ic|~/.ssh}} directory and {{ic|authorized_keys}} file. To prevent this, set the immutable bit on the {{ic|~/.ssh}} directory too. {{Note|If you find yourself needing to add a new key, you will first have to remove the immutable bit from {{ic|authorized_keys}} and make it writable. Follow the steps above to secure it again.}} ===パスワードログインの無効化=== While copying your public key to the remote SSH server eliminates the need to transmit your password over the network, it does not give any added protection against a brute-force password attack. In the absence of a private key, the SSH server will fall back to password authentication by default, thus allowing a malicious user to attempt to gain access by guessing your password. To disable this behavior, edit the following lines in the {{ic|/etc/ssh/sshd_config}} file on the remote server. {{hc|/etc/ssh/sshd_config| PasswordAuthentication no ChallengeResponseAuthentication no}} === 2段階認証と公開鍵 === Since OpenSSH 6.2, you can add your own chain to authenticate with using the {{ic|AuthenticationMethods}} option. This enables you to use public keys as well as a two-factor authorization. See [[Google Authenticator]] to set up Google Authenticator. To use PAM with OpenSSH, edit the following files: {{hc|/etc/ssh/sshd_config| ChallengeResponseAuthentication yes AuthenticationMethods publickey keyboard-interactive:pam }} Then you can log in with either a publickey, or a password+verification code combination. ==SSH エージェント== If your private key is encrypted with a passphrase, this passphrase must be entered every time you attempt to connect to an SSH server using public-key authentication. Each individual invocation of {{ic|ssh}} or {{ic|scp}} will need the passphrase in order to decrypt your private key before authentication can proceed. An SSH agent is a program which caches your decrypted private keys and provides them to SSH client programs on your behalf. In this arrangement, you must only provide your passphrase once, when adding your private key to the agent's cache. This facility can be of great convenience when making frequent SSH connections. An agent is typically configured to run automatically upon login and persist for the duration of your login session. A variety of agents, front-ends, and configurations exist to achieve this effect. This section provides an overview of a number of different solutions which can be adapted to meet your specific needs. ===ssh-agent=== ssh-agent is the default agent included with OpenSSH. It can be used directly or serve as the back-end to a few of the front-end solutions mentioned later in this section. When {{ic|ssh-agent}} is run, it will fork itself to the background and print out the environment variables it would use. $ ssh-agent SSH_AUTH_SOCK=/tmp/ssh-vEGjCM2147/agent.2147; export SSH_AUTH_SOCK; SSH_AGENT_PID=2148; export SSH_AGENT_PID; echo Agent pid 2148; To make use of these variables, run the command through the {{ic|eval}} command. $ eval $(ssh-agent) Agent pid 2157 You can append the above command to your {{ic|~/.bash_profile}} script so that it will run automatically when starting a login shell. $ echo 'eval $(ssh-agent)' >> ~/.bash_profile Once {{ic|ssh-agent}} is running, you will need to add your private key to its cache. $ 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) If you would like your private keys to be added automatically on login. Add the following command to your {{ic|~/.bash_profile}} as well. $ ssh-add If your private key is encrypted, {{ic|ssh-add}} will prompt you to enter your passphrase. Once your private key has been successfully added to the agent you will be able to make SSH connections without having to enter a passphrase. If you would prefer not to be prompted for your passphrase until your key is needed, adding $ ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' to {{ic|~/.bashrc}} will cause {{ic|ssh-add}} to be run when needed and destroy the alias afterwards. One downside to this approach is that a new instance of {{ic|ssh-agent}} is created for every login shell and each instance will persist between login sessions. Over time you can wind up with dozens of needless {{ic|ssh-agent}} processes running. There exist a number of front-ends to ssh-agent and alternative agents described later in this section which avoid this problem. Another downside is that the key will not be added by commands other than ssh that use the private key, such as many git commands. ====systemd ユーザーで ssh-agent を起動==== [[Systemd/ユーザー]]機能を使ってエージェントを起動することができます。{{ic|~/.config/systemd/user}} フォルダに以下のユニットファイルを配置してください: {{hc|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>''MyTarget''.target }} Add {{ic|1=export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"}} to your shell's startup file, for example {{ic|.bash_profile}} for [[Bash]]. Then enable and start the service. ====ssh-agent をラッパープログラムとして使う==== An alternative way to start ssh-agent (with, say, each X session) is described in [http://upc.lbl.gov/docs/user/sshagent.shtml this ssh-agent tutorial by UC Berkeley Labs]. A basic use case is if you normally begin X with the {{ic|startx}} command, you can instead prefix it with {{ic|ssh-agent}} like so: $ 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 [[#Calling_x11-ssh-askpass_with_ssh-add|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|If you are using KDE and have {{Pkg|kde-agent}} installed you only need to set {{ic|enable-ssh-support}} into {{ic|~/.gnupg/gpg-agent.conf}}! Otherwise, continue reading.}} To start using GnuPG agent for your SSH keys, you should first start ''gpg-agent'' with the {{ic|--enable-ssh-support}} option. Example (do not forget to make the file executable): {{hc|/etc/profile.d/gpg-agent.sh|<nowiki> #!/bin/sh # Start the GnuPG agent and enable OpenSSH agent emulation gnupginf="${HOME}/.gpg-agent-info" if pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then eval `cat $gnupginf` eval `cut -d= -f1 $gnupginf | xargs echo export` else eval `gpg-agent -s --enable-ssh-support --daemon --write-env-file "$gnupginf"` fi </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... {{Note|{{ic|gpg-agent.conf}} must be created, and the variable {{ic|write-env-file}} must be set in order to allow ''gpg-agent'' keys to be injected to SSH across logins, unless you restart ''gpg-agent'', and therefore, export its settings, with every login.}} {{hc|~/.gnupg/gpg-agent.conf|<nowiki> # Environment file write-env-file /home/username/.gpg-agent-info # 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>}} To use the agent, you can then source and export the environment variables that ''gpg-agent'' writes in {{ic|.gpg-agent-info}}, which is the file specified with {{ic|write-env-file}}. {{hc|~/.bashrc|<nowiki> ... if [ -f "${HOME}/.gpg-agent-info" ]; then . "${HOME}/.gpg-agent-info" export GPG_AGENT_INFO export SSH_AUTH_SOCK fi </nowiki>}} ===Keychain=== [http://www.funtoo.org/Keychain Keychain] is a program designed to help you easily manage your SSH keys with minimal user interaction. It is implemented as a shell script which drives both ''ssh-agent'' and ''ssh-add''. A notable feature of Keychain is that it can maintain a single ''ssh-agent'' process across multiple login sessions. This means that you only need to enter your passphrase once each time your local machine is booted. [[pacman|Install]] the {{Pkg|keychain}} package, available from the [[official repositories]]. Append the following line to {{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=== An alternative to keychain is [https://github.com/vodik/envoy envoy]. Envoy is available as {{Pkg|envoy}} in the [[official repositories]], or the Git version is in the [[AUR]] as {{AUR|envoy-git}}. After installing it, set up the envoy socket with # systemctl enable envoy@ssh-agent.socket 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 に キーパスフレーズを保存==== If you have long passphrases for your SSH keys, remembering them can be a pain. So let us tell kwallet to store them! Along with {{Pkg|envoy}}, install {{Pkg|ksshaskpass}} and {{Pkg|kdeutils-kwalletmanager}} from the [[official repositories]]. Next, enable the envoy socket in systemd (see above). First, you will add this script to {{ic|~/.kde4/Autostart/ssh-agent.sh}}: #!/bin/sh envoy -t ssh-agent -a ''ssh_key'' Then, make sure the script is executable by running: {{ic|chmod +x ~/.kde4/Autostart/ssh-agent.sh}} And add this to {{ic|~/.kde4/env/ssh-agent.sh}}: #!/bin/sh eval $(envoy -p) When you log into KDE, it will execute the {{ic|ssh-agent.sh}} script. This will call ''ksshaskpass'', which will prompt you for your kwallet password when envoy calls ''ssh-agent''. ===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. Install {{Pkg|keychain}} and {{Pkg|x11-ssh-askpass}}, both available in the [[official repositories]]. 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_as_a_wrapper_program|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. ====テーマ==== The appearance of the ''x11-ssh-askpass'' dialog can be customized by setting its associated [[X resources]]. The ''x11-ssh-askpass'' [http://www.jmknoble.net/software/x11-ssh-askpass/ home page] presents some [http://www.jmknoble.net/software/x11-ssh-askpass/screenshots.html example themes]. See the ''x11-ssh-askpass'' manual page for full details. ====他のパスフレーズダイアログ==== There are other passphrase dialog programs which can be used instead of ''x11-ssh-askpass''. The following list provides some alternative solutions. * {{Pkg|ksshaskpass}} is available in the official repositories. It is dependent on {{Pkg|kdelibs}} and is suitable for the [[KDE]] Desktop Environment. * {{Pkg|openssh-askpass}} depends on the {{Pkg|qt4}} libraries and is available from the official repositories. ===pam_ssh=== The [http://pam-ssh.sourceforge.net/ pam_ssh] project exists to provide a [[Wikipedia:Pluggable authentication module|Pluggable Authentication Module]] (PAM) for SSH private keys. This module can provide single sign-on behavior for your SSH connections. On login, your SSH private key passphrase can be entered in place of, or in addition to, your traditional system password. Once you have been authenticated, the pam_ssh module spawns ssh-agent to store your decrypted private key for the duration of the session. To enable single sign-on behavior at the tty login prompt, install the unofficial {{AUR|pam_ssh}} package, available in the [[Arch User Repository]]. {{Note|pam_ssh 2.0 now requires that all private keys used in the authentication process be located under {{ic|~/.ssh/login-keys.d/}}.}} Create a symlink to your private key file and place it in {{ic|~/.ssh/login-keys.d/}}. Replace the {{ic|id_rsa}} in the example below with the name of your own private key file. $ mkdir ~/.ssh/login-keys.d/ $ cd ~/.ssh/login-keys.d/ $ ln -s ../id_rsa Edit the {{ic|/etc/pam.d/login}} configuration file to include the text highlighted in bold in the example below. The order in which these lines appear is significiant and can affect login behavior. {{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]] の記事を見て下さい。 ==トラブルシューティング== 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 鍵のソースを表示
話題を追加