SSHサーバー構築

外からサーバのアクセスをSSHで行う手順。
パスワード認証ではなく、鍵での認証のみとします。

OpenSSH2 の鍵生成

% ssh-keygen -b 1024 -t rsa
% cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
% chmod 600 ~/.ssh/authorized_keys

公開鍵セットアップ

作成した鍵ペアでSSHサーバーへ鍵方式ログインできるように公開鍵をセットアップする。
# mkdir -p ~/.ssh
# chmod 700 ~/.ssh
# vi ~/.ssh/authorized_keys
# ssh-dss xxxxx・・・xxxxx
# chmod 600 ~/.ssh/authorized_keys

SSHサーバー設定

# vi /etc/ssh/sshd_config
SSHサーバー設定ファイル編集
#Protocol 2,1

Protocol 2 ← SSH2のみで接続を許可

#PermitRootLogin yes

PermitRootLogin no ← rootでのログインを禁止

#PasswordAuthentication yes

PasswordAuthentication no ← パスワードでのログインを禁止(鍵方式によるログインのみ許可)

#PermitEmptyPasswords no

PermitEmptyPasswords no ← パスワードなしでのログインを禁止


SSHサーバー再起動

# /etc/rc.d/init.d/sshd restart



ルーター側の設定でポート22番をOPENする。