sshでXを飛ばす
ssh/PortForwardSSH
SSHホストベース認証
ssh/ssh-agent
ssh/UsePAM?
公開鍵を多サーバーへ登録 †
多サーバーへの authorized_keys へ公開鍵を追記するのは結構面倒. ファイルを転送して追記と.
っで簡単にする方法があって「ssh-copy-id」コマンド
[illya@c ~]$ ssh-copy-id root@ms
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/illya/.ssh/id_dsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@ms's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@ms'"
and check to make sure that only the key(s) you wanted were added.
[illya@c ~]$
この場合「/home/illya/.ssh/id_dsa.pub」が送られます. もし .ssh/id_rsa.pub を送りたければ
[illya@c ~]$ ssh-copy-id -i .ssh/id_rsa root@ms
とします。
これは「openssh-clients」パッケージに同封されている
鍵作成 †
大抵はssh-keygen -t dsaでパスフレーズを入力して鍵が得られます。
パスフレーズを別に入れなくて、リターンキーで返しても鍵は作れます。下記は、ファイル名を指定して鍵を作る場合です。
local $ ssh-keygen -t dsa -b 1024 -f id_remote <----- 鍵のファイル名を id_remote としてます。
enerating public/private dsa key pair.
Enter passphrase (empty for no passphrase): <----- パスフレーズ入力。パスフレーズなしなら、リターンキーを押す
Enter same passphrase again: <----- パスフレーズを再入力。パスフレーズなしなら、リターンキーを押す
Your identification has been saved in id_remote.
Your public key has been saved in id_remote.pub.
The key fingerprint is:
ce:d--------------------76:b5 foo@local
The key's randomart image is:
+--[ DSA 1024]----+
| .=+o=++. ..|
| +o ++.. .|
| .. =oo. E |
| = + |
| S . |
| + |
| o |
| |
| |
+-----------------+
#
っで-fを指定したことで、実行した場所に
- 秘密鍵 id_remote
- 公開鍵 id_remote.pub
の2つ一組の鍵が作られます。
もし-fの指定がないと、使う暗号方式によるが
- 秘密鍵 $HOME/.ssh/id_dsa
- 公開鍵 $HOME/.ssh/id_dsa.pub
と既定の場所、ファイル名となる
つかう †
公開鍵(id_remote.pub、既定ではid_dsa.pub)をsshで接続したいサーバに送ります。ftpとか、usbメモリーとかで。
local $ ftp remote
ftp> pub id_remote.pub
ftp> bye
そして、相手先でsshで接続したいアカウントにこの公開鍵を含んだファイル(authorized_keys)を作ります。authorized_keysファイルには複数の公開鍵が含ませても構いません。
remote $
remote $ mkdir .ssh; chmod 700 .ssh
remote $ cat id_remote.pub >> .ssh/authorized_keys *このファイル名は接続先の/etc/ssh/sshd_configのAuthorizedKeysFileで決まる
remote $ chmod 600 .ssh/authorized_keys
remote $ rm id_remote.pub
これでパスフレーズを使ってのssh接続の準備は整いました。パスフレーズを持たない公開鍵であっても同様にauthorized_keysファイルを作ります。
接続する相手方(remote)の/etc/ssh/sshd_configの内容が、
PasswordAuthentication yes
なら、明示的に秘密鍵ファイルを指定すると、パスフレーズを問われ、
(割符が合わなければ)次に接続先のユーザの/etc/passwdを問われます。
local $ ssh -i ~/.ssh/id_remote -l foo remote <--- (-i)で手元に残った秘密鍵のファイルを指定します。
Enter passphrase for key '/home/foo/.ssh/id_remote ': <--- パスフレーズ入力
foo@remote's password: <--- /etc/passwdのパスワード
remote $
パスフレーズのみを使うのであれば、接続先(remote)の/etc/ssh/sshd_configは
PasswordAuthentication no
とする。
ちなみに接続先(remote)の/etc/ssh/sshd_configで
は、/etc/passwdでのパスワードがNULL禁止であって、パスフレーズがない公開鍵・秘密鍵には関わっていないようだ