SSHサーバのインストールとクライアント認証による接続の準備
Debianインストール後,SSHでクライアント認証によりログインするための環境を準備しました.
手順
- openssh-server をインストール
# apt-get install openssh-server
- /etc/ssh/sshd_config を編集.以下の設定を入れる
PasswordAuthentication no PermitRootLogin no PermitEmptyPassword no AllowUsers RSAAuthentication yes PubkeyAuthentication yes RhostsRSAAuthentication no
これで,パスワード認証での接続はできなくなり,公開鍵暗号方式での接続のみになりました.
接続を試みた場合,Permission denied (publickey). で,エラーになります.
鍵を作る
- ローカル側で,ログインしたいユーザで鍵ファイルをつくる.
$ ssh-keygen -b 1024 -t dsa
すると次の2つのファイルができます.
~/.ssh/id_dsa (dsa秘密鍵) ~/.ssh/id_dsa.pub (dsa公開鍵)
・id_dsa.pub をSSH接続先となるホストへ移す.今回は一時的にパスワード認証を許可して scp でコピー.
$ scp id_dsa.pub foo@<server_ip>:id_dsa.pub
・サーバ側で,authorized_keys というファイルに追記し,パーミッション変更
$ cat id_dsa.pub >> ~/.ssh/authorized_keys $ chmod 600 ~/.ssh/authorized_keys