CentOS5 SSHサーバー設定

直接CentOS触るのもいいけど、2つもキーボード置けないでリモートでアクセスできるように構築。

sshd_config設定

[root@localhost ~]# vi /etc/ssh/sshd_config

#Protocol 2,1
↓ コメント解除、ssh2のみに変更
Protocol 2

#PermitRootLogin yes
↓ コメント解除、rootでのログイン禁止
PermitRootLogin no

#PermitEmptyPasswords no
↓ コメント解除、パスワード未設定のユーザのログインを禁止
PermitEmptyPasswords no

一応ローカルでの接続前提なので鍵項目はスルー。今後鍵でのログインをする場合以下の設定を変更する必要あり。

[root@localhost ~]# vi /etc/ssh/sshd_config

#PasswordAuthentication yes
↓ 鍵方式のログインのみに変更
PasswordAuthentication no

hosts.allow、hosts.denyの設定

ここでsshにアクセスできるホストを設定。

[root@localhost ~]# vi /etc/hosts.allow

#
# hosts.allow This file describes the names of the hosts which are
#       allowed to use the local INET services, as decided
#        by the '/usr/sbin/tcpd' server.
#

sshd: 127.0.0.1
↑サーバ自身のsshアクセス許可
sshd: 192.168.1.
↑ローカルネットワークからの(192.168.1.XXXからの)sshアクセス許可

[root@localhost ~]# vi /etc/hosts.deny

#
# hosts.deny  This file describes the names of the hosts which are
#       *not* allowed to use the local INET services, as decided
#       by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!

sshd: ALL
↑hosts.allowの記述以外のアクセスを禁止

一応ローカルネットワーク以外のアクセスを遮断。必要なら、hosts.allowのほうに
sshd: .ppp.u-netsurf.ne.jp(XXX.ppp.u-netsurf.ne.jpのアクセス許可)』
のように設定すればOK

SSHサーバー再起動

設定を反映させるためにリスタート

[root@localhost ~]# /etc/rc.d/init.d/sshd restart
sshd を停止中:       [ OK ]
sshd を起動中:       [ OK ]

後はポート22番を空けてあげればOK。外からのアクセス不要なら閉じたまま。