スクリーンショット 2014 01 14 0 57 14 7

こんにちは、ジュン@jun3010meです。

この度、当ブログはエックスサーバーからさくらのVPSに移行しました。

その際の設定記録をここに残しておきたいと思います。

rootのパスワードを変更する

[root@www ~]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

さくらVPSを借りたら、まずはrootのパスワードをメールで送られてきたものから、

自分のパスワードに変更しておきましょう。

ユーザを追加する

[root@www ~]# useradd wordpress
[root@www ~]# passwd wordpress
Changing password for user wordpress.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@www ~]# usermod -G wheel wordpress

root以外で自分が使うユーザを作成し、rootにsuできるユーザとします。

[root@www ~]# vi /etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         optional        pam_xauth.so

また、rootになれるユーザは、ここで追加したユーザのみとします。

viの操作メモ

Linuxのコマンドライン上では、vimというテキストエディタを使います。

vimは普通のエディタと操作方法が異なり、慣れていない人だと戸惑います。

 

簡単な操作方法としては、

hjklがそれぞれ←↓↑→移動

iで入力モード,escで抜ける

xで1字削除

:wq+Enterで上書き保存

:q!+Enterで保存せずに閉じる

が使えると作業がスムーズになると思います。

SSHの設定をする

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

/etc/ssh/sshd_configを次の通りに書き換えます

$OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
 
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
 
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
 
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.
 
Port 90022
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
 
# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1

Protocol 2

# Authentication:
 
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

#MaxSessions 10 

特にポート番号が22番のままだと攻撃の対象となる可能性が高いので、他の番号にします。

また、SSH接続でrootでのログインを禁止して、先ほど作成したユーザでログオンするようにします。

[root@www ~]# /etc/rc.d/init.d/sshd start
Starting sshd: [  OK  ]

これでSSHが起動します。

最低限の初期設定が完了!

セキュリティ対策が万全とは呼べないかもしれませんが、

パスワードの変更、ユーザの追加、SSHの設定まで済ませました。

 

これ以降は、コンソールページからではなく、

MacのターミナルやWindowsのTeraTermProなどの

ターミナルアプリから操作するようにしていきましょう。

今回はここまで!お疲れ様でしたヽ(=´▽`=)ノ

 

よりセキュリティ対策を行い、サーバを運用したい方は、こちらの書籍をオススメします(`・ω・´)ゞ