Last Updated on 2022年3月13日 by かんりにん
[pukiwiki]
 
**▼ssh 公開鍵認証と公開鍵の登録 [#q473bc7b]
作業自体は簡単なんですが
ユーザー名やらいろいろこんがらがるので、メモを作成します。
”【ローカル側ホスト】”サーバへログインしたいクライアント側のアカウント
ホスト名:client
ユーザ名:yeah
”【リモート側サーバ】”リモートでログインされるサーバ側のアカウント
ホスト名:example
サーバ名:svruser
***1)クライアントで公開鍵を生成 [#w52c8984]
ローカル側ホストで、ログインしたいユーザになり
公開鍵・秘密鍵を作成します。
ここではDSAキーを生成してますが
RSAキーでもOK。
 [root@client root]# su – yeah
 [yeah@client yeah]$ ssh-keygen -d
 Generating public/private dsa key pair.
 Enter file in which to save the key (/home/yeah/.ssh/id_dsa):		←このままEnterでOK
 Created directory ‘/home/yeah/.ssh’.
 Enter passphrase (empty for no passphrase):			←パスフレーズを入力
 Enter same passphrase again:					←再度フレーズを入力
 Your identification has been saved in /home/yeah/.ssh/id_dsa.
 Your public key has been saved in /home/yeah/.ssh/id_dsa.pub.
 The key fingerprint is:
 46:f9:72:d9:d4:9e:44:4b:24:be:3c:d6:5c:a3:d5:41 yeah@client.org
 [yeah@client yeah]$
生成されたDSAキーを確認。
公開鍵はid_dsa.pub。
 [yeah@client yeah]$ ls -al .ssh/
 合計 20
 drwx——    2 yeah     yeah         4096  4月  4 15:20 .
 drwx——    5 yeah     yeah         4096  4月  4 15:18 ..
 -rw——-    1 yeah     yeah          668  4月  4 15:18 id_dsa
 -rw-r–r–    1 yeah     yeah          610  4月  4 15:18 id_dsa.pub
 -rw-r–r–    1 yeah     yeah          222  4月  4 15:20 known_hosts
 [yeah@client yeah]$
※今回は鍵認証のみで、パスフレーズは入力していません。
***2)サーバ側で公開鍵を登録 [#gad34312]
SCPやフロッピーなどでサーバへ公開鍵を移し、
authorized_keyへ登録します。
※サーバ側で生成したid_dsaがありますが
 間違えないように注意!
 [svruser@example ~]$ pwd
 /home/svruser/.ssh
 [svruser@example .ssh]$  ls -al .ssh/
 drwx——    2 user     user         4096  4月  4 15:20 .
 drwxr-xr-x   19 user     user         4096  4月  4 15:20 ..
 -rw-r–r–    1 user     user        11609  4月  4 15:20 authorized_keys
 -rw——-    1 user     user          736  8月 31  2004 id_dsa		←これは無関係
 -rw-r–r–    1 user     user          601  8月 31  2004 id_dsa.pub		←これも無関係
 -rw——-    1 user     user          951  3月  7 18:40 id_rsa
 -rw-r–r–    1 user     user          221  3月  7 18:40 id_rsa.pub
 -rw-r–r–    1 user     user         6296  3月 31 22:48 known_hosts
 [svruser@example ~]$
 [svruser@example ~]$ cat id_dsa.pub >> authorized_keys
***3)ログインテスト [#gf98bfef]
サーバ側で公開鍵を登録したユーザーを指定し、
公開鍵を作成したユーザーでログイン。
初めてログインするホストの場合は“このまま続けるか?”と警告が出ますが
そのまま“yes”で継続。
 [yeah@client yeah]$ ssh svruser@***.***.***.***
 The authenticity of host ‘***.***.***.*** (***.***.***.***)’ can’t be established.
 RSA key fingerprint is 9a:**:c6:e1:**:d9:8c:46:**:86:**:69:3a:**:3f:0d.
 Are you sure you want to continue connecting (yes/no)? yes			←“yes”を入力
 Warning: Permanently added ‘***.***.***.***’ (RSA) to the list of known hosts.
 Last login: Mon Apr  4 15:18:20 2005 from ***-***-***-***.hoge.example.tld
 [svruser@example svruser]$
上記でログイン確認OK。
※今回はパスフレーズを省略したので、次回からはパスワード無しで
 ログインできてますが、パスフレーズは必ず設定しましょう。
[/pukiwiki]
 
 
											