SSH(TTSSH)の設定方法(Version1、2対応版)



●SSHプロトコルVersion.1で利用するRSAキーの作成

  $ ssh-keygen -t rsa1
  Generating public/private rsa1 key pair.
  Enter file in which to save the key (/home/totoro/.ssh/identity):(リターン)
  Created directory '/home/totoro/.ssh'.
  Enter passphrase (empty for no passphrase):(パスフレーズの入力)
  Enter same passphrase again:(再度パスフレーズの入力)
  Your identification has been saved in /home/totoro/.ssh/identity.
  Your public key has been saved in /home/totoro/.ssh/identity.pub.
  The key fingerprint is:
  f7:f5:56:3d:ca:83:13:20:fe:c1:37:9f:3e:67:3f:bb totoro@test.try.local
 identity.pubをauthorized_keysとしてコピーする。
  $ cp /home/totoro/.ssh/identity.pub /home/totoro/.ssh/authorized_keys
 authorized_keysのアクセス権が600でないとサーバに接続できないことがあるので、モード変更する。
  $ chmod 600 /home/totoro/.ssh/authorized_keys
 確認する。
  $ ls -l /home/totoro/.ssh/
  合計 3
  -rw-------    1 totoro    totoro         342 Jun 15 23:43 authorized_keys
  -rw-------    1 totoro    totoro         538 Jun 15 23:41 identity
  -rw-r--r--    1 totoro    totoro         342 Jun 15 23:41 identity.pub
 上記のようになっていれば、OK。

 TTSSHを利用して、RSA(ユーザベース)認証でログインしたい場合は適当なフォルダ(例はTTSSHをインストールしているフォルダTTERMPRO)にidentityを保存する。(FTPでダウンロードしてくる場合はbinaryでgetすること。asciiでgetするとTTSSHからログインできない。)これで、WindowsからTTSSHを利用してRSA認証でログインできる。もし、できない場合は、authorized_keysをidentityから作成してないか確認してほしい。



 ただし、このままではLinux同士のRSA認証でのログインができず、以下のように表示される。
  Permission denied (publickey,keyboard-interactive).
 この場合は以下のようにしてほしい。
  # vi /etc/ssh/sshd_config
           :
           :
    # HostKey for protocol version 1
    #HostKey /etc/ssh/ssh_host_key ← コメントアウトする
    # HostKeys for protocol version 2
    #HostKey /etc/ssh/ssh_host_rsa_key
    #HostKey /etc/ssh/ssh_host_dsa_key
           :
    #RSAAuthentication yes ← コメントアウトする
           :
           :
sshdを再起動。
  # /etc/rc.d/init.d/sshd restart
  sshdを停止中:                                              [  OK  ]
  sshdを起動中:Disabling protocol version 2. Could not load host key
                                                       [  OK  ]
 「Disabling protocol version 2. Could not load host key」が表示されるのは、上記のsshd_configで「#HostKey /etc/ssh/ssh_host_rsa_key、#HostKey /etc/ssh/ssh_host_dsa_key」の2行がコメントアウトされていないからである。  バージョン1のRSA認証でログインできるか確認する。
  $ ssh localhost
  The authenticity of host 'localhost (127.0.0.1)' can't be established.
  RSA1 key fingerprint is 1f:69:83:b8:21:10:1e:fb:59:eb:4e:55:a3:0b:84:b7.
  Are you sure you want to continue connecting (yes/no)? yes
     ↑ sshで初めて接続する場合に問われる。「yes」と入力
  Warning: Permanently added 'localhost' (RSA1) to the list of known hosts.
  Enter passphrase for RSA key '/home/totoro/.ssh/identity':(パスフレーズを入力)
  Last login: Sun Jun 16 00:15:28 2002 from localhost.localdomain
 ログインできたら PasswordAuthentication no として、sshdを再起動しよう。

 また、Linux同士の場合「#HostKey /etc/ssh/ssh_host_rsa_key、#HostKey /etc/ssh/ssh_host_dsa_key」の2行をコメントアウトして、sshdを再起動してもログイン時に「Permission denied (publickey,keyboard-interactive).」が表示されて、SSHプロトコルVersion.1 RSA認証で何故かログインできない。
 ★上記解決 以下のように強制的にバージョン1を指定してログインする。
  $ ssh -1 localhost

 SSHプロトコルVersion.1では、sftpは何故か利用できない。現象は上記と同じで「Permission denied (publickey,keyboard-interactive).」が表示される。
 ★上記解決 以下のように強制的にバージョン1を指定してログインする。
  $ sftp -1 localhost
 SSHプロトコルVersion.1では、scpは何故か利用できない。現象は上記と同じで「Permission denied (publickey,keyboard-interactive).」が表示される。
 ★上記解決 以下のように強制的にバージョン1を指定してログインする。
  $ scp -oProtocol=1 [[user@]host1:]file1 [...] [[user@]host2:]file2
●SSHプロトコルVersion.2で利用するDSAキーの作成

  ssh-keygen -t dsa
  Generating public/private dsa key pair.
  Enter file in which to save the key (/home/totoro/.ssh/id_dsa):
  Enter passphrase (empty for no passphrase):
  Enter same passphrase again:
  Your identification has been saved in /home/totoro/.ssh/id_dsa.
  Your public key has been saved in /home/totoro/.ssh/id_dsa.pub.
  The key fingerprint is:
  b8:f9:8f:03:fc:6e:73:a5:6b:e1:4c:9e:b6:cd:3b:c5 totoro@test.try.local
 id_dsa.pubをauthorized_keys2としてコピーする。
  $ cp /home/totoro/.ssh/id_dsa.pub /home/totoro/.ssh/authorized_keys2
  $ chmod 600 /home/totoro/.ssh/authorized_keys2(これは実行しなくてもよい)
作成されているか確認する。
  $ ls -l /home/totoro/.ssh
  合計 6
  -rw-------    1 totoro    totoro         342 Jun 15 23:43 authorized_keys
  -rw-------    1 totoro    totoro         613 Jun 16 12:15 authorized_keys2
  -rw-------    1 totoro    totoro         736 Jun 16 12:14 id_dsa
  -rw-r--r--    1 totoro    totoro         613 Jun 16 12:14 id_dsa.pub
  -rw-------    1 totoro    totoro         538 Jun 15 23:41 identity
  -rw-r--r--    1 totoro    totoro         342 Jun 15 23:41 identity.pub
 sshd_configの設定。
  # vi /etc/ssh/sshd_config
         :
         :
  # HostKey for protocol version 1
  HostKey /etc/ssh/ssh_host_key
  # HostKeys for protocol version 2
  #HostKey /etc/ssh/ssh_host_rsa_key
  #HostKey /etc/ssh/ssh_host_dsa_key ← コメントアウトする
         :
         :
 sshdを再起動。
  # /etc/rc.d/init.d/sshd restart
  sshdを停止中:                                              [  OK  ]
  sshdを起動中:                                              [  OK  ]
 SSHのバージョンを指定してDSA認証によるログインを確認する。
  $ ssh -2 localhost
  The authenticity of host 'localhost (127.0.0.1)' can't be established.
  DSA key fingerprint is d3:8f:53:50:f1:f5:2d:3c:f1:9e:5e:54:a4:7c:ee:52.
  Are you sure you want to continue connecting (yes/no)? yes
     ↑ sshで初めて接続する場合に問われる。「yes」と入力
  Warning: Permanently added 'localhost' (DSA) to the list of known hosts.
  Enter passphrase for key '/home/totoro/.ssh/id_dsa':(パスフレーズを入力)
  Last login: Sun Jun 16 11:21:28 2002 from localhost.localdomain
 ログインできればOK。