さくらのVPSに申し込みをした。
このVPSの設定をすれば、先日取得したドメインも使えるというものである。

とりあえず、VPSコントロールパネルにアクセスし、VPSを起動。
まずはどこのVPSでもやることは一緒のセキュリティ対策である。

まずは、VPSのリモートコンソールにあるVNCコンソールを使ってrootでloginする。
どうもVPSリモートコンソールは使いにくい。
本当はTeraTermなどのターミナルソフトでアクセスしたかったのだが、アクセスできなかった。
なので、VNCコンソールを使ったのである。


早速、以下の通りでrootのパスワード変更から、ユーザ登録まで行った。

# passwd 
Changing password for user root. 
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

# groupadd hoge
# useradd -G hoge hoge
# passwd hoge
Changing password for user hoge. 
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
# vi /etc/ssh/sshd_config

ssh でアクセスするポートを標準の22番ポートから *****ポートに変更、また以下のように設定。

# Port 22
Port *****
# SSHのプロトコルをSSH2のみ対応に
Protocol 2
# rootでのログイン不可
PermitRootLogin no
# パスワードでのログイン許可
PasswordAuthentication yes
# パスワードなしでのログイン不可
PermitEmptyPasswords no
# hoge というユーザだけログイン許可
AllowUsers hoge

設定ファイルを変更したのち、sshdの再起動。

# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
# su – hoge
# touch .ssh/authorized_keys
# chmod 600 .ssh/authorized_keys

TeraTermのメニュー[設定]-[SSH鍵生成]で公開鍵と秘密鍵を生成する。
id_rsa, id_rsa.pubという2ファイルを生成。

このうち、id_rsa.pubを.ssh/authorized_keys にコピー。
これで teraterm の 「RSA/DSA鍵を使う」でのログインが可能となった。
この対応により、再度/etc/ssh/sshd_config を編集。
先程設定したPasswordAuthentication の値を変更する。

# パスワードでのログイン不可
PasswordAuthentication no

# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

これで鍵がないとアクセスできなくなった。
実際に、ID/PWによるSSHでアクセス不可のエラーとなった。

続いて、rootへのダイレクトアクセスを極力なくすために、sudoの設定を行う。

# visudo
hoge     ALL=(ALL)      ALL

を追加。
試しにユーザ hoge で、通常はできないことをやってみる。

# cat sshd_config
cat: sshd_config: Permission denied
# sudo -u root cat sshd_config
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for hoge:
#       $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
・・・・・・・・・・・・・
・・・・・・・・・・・・・

ということで、一通り設定が終了。
再度、root に戻ってシステムのアップデートである。

# yum update
・・・・・・・・・・・・・
・・・・・・・・・・・・・
Transaction Summary
================================================================================
Install       2 Package(s)
Upgrade      58 Package(s)

Total download size: 95 M
Is this ok [y/N]: y
・・・・・・・・・・・・・
・・・・・・・・・・・・・
Total                                            20 MB/s |  95 MB     00:04
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
updates/gpgkey                                           | 1.5 kB     00:00
Importing GPG key 0xE8562897 “CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>” from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
・・・・・・・・・・・・・
・・・・・・・・・・・・・
Complete!

他の人のブログを読んだりすると、ssh へのアタックがすごい、とのことなので、ちょっとログを見る。
アタックは皆無だったが、何だかエラーが出ていた。

# view /var/log/secure

error: Bind to port ***** on 0.0.0.0 failed: Address already in use.

ちょっとこのエラーがうざいので、ググって調べる。
どうやらIPv6の関係らしい。ということで、ググって以下のコメントをはずして有効に。

# vi /etc/ssh/sshd_config

ListenAddress 0.0.0.0

# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

しっかし、本当になんにも入ってないなぁ…。
とにかく Webサーバをインストールして、早くDNS登録、Google Apps の登録をしよっと。

とりあえず、今日の設定はここまで。

, ,
Trackback

no comment untill now

Add your comment now

*