やってきた記録はやっぱり残しておいた方がよい,ということで,初期設定からWordPressをインストール・引っ越しまでの記録を残していきます。
なお,環境としてはLEMP(Linux(CentOS6)・nginx(これがE)・MariaDB・PHP)で行こうかと思います。(この環境のユーザーが意外にいなかったので,記録を残す価値はあるかな,と。(特に初心者向けに))
一般ユーザーの追加
rootユーザーだけでは権限が強すぎて危険なので,一般ユーザーの追加を行ないます。
[root@localhost ~]# useradd [user] [root@localhost ~]# passwd [user] Changing password for user [user]. New password: 【パスワード入力】 Retype new password: 【パスワード入力】 passwd: all authentication tokens updated successfully.
一般ユーザーでログインできるか確認しておきます。
SAKURA Internet [Virtual Private Server SERVICE] [user@localhost ~]$
これでOKです。
sudoの設定
sudoが使えるwheelグループに追加します。
[root@localhost ~]# usermod -G wheel [user]
そしてwheelグループがsudoを使えるようにします。
[root@localhost ~]# visudo
編集内容
## Allows members of the 'sys' group to run networking, software, ## service management apps and more. # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVE RS ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL → %wheel ALL=(ALL) ALL (コメントアウト削除)
例えばこんなことが出来ます。
[user@localhost ~]$ sudo su - 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 user: 【パスワード入力】 [root@localhost ~]#
公開鍵認証によるSSH接続
RLoginを用いて公開鍵認証によるSSH接続にします。(クライアントソフト選びは永遠の課題)
サーバー接続の編集からプロトコルに行き,認証キーを選択します。
下部にある『新規』の『作成』から認証キーを作成します。名前をつけておいた方がよいかもしれません。
パスフレーズを決めて決定です。
認証キーを保存しておきます。ファイル名は初期値でよいかと思います。
公開鍵を手に入れるべく,先程作成した認証キーを選択し,公開鍵へ行きます。
公開鍵が出るので,これをコピーしておきます。
TOPに戻り,秘密鍵を読み込む設定をします。
あとは接続の設定です。
[user@localhost ~]$ mkdir .ssh #.sshフォルダの作成 [user@localhost ~]$ chmod 700 .ssh #.sshフォルダを700設定に [user@localhost ~]$ cd .ssh #.sshに移動 [user@localhost .ssh]$ vim authorized_keys #公開鍵を作成 [user@localhost .ssh]$ chmod 600 authorized_keys #公開鍵を600に
SSH接続の設定
SSH接続の設定をまとめて行ないます。
[root@localhost ~]# vim /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 22 → Port [PortNo.] #ポート番号変更。 (中略) #PermitRootLogin yes → PermitRootLogin no #rootログインの不許可 (中略) PasswordAuthentication yes → PasswordAuthentication no #パスワードによるログインの不許可
あとはSSHを再起動しておきましょう。
[root@localhost ~]# /etc/init.d/sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]
最後にポート番号変更してログイン出来るか確認です。(出来なかったらやり直し。)
iptablesの設定
さくらのVPSのやり方でもよいのですが,1行1行入力するのが面倒なので,設定ファイルをいじります。
[root@localhost ~]# sudo vim /etc/sysconfig/iptables
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :RH-Firewall-1-INPUT - [0:0] -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p 50 -j ACCEPT -A RH-Firewall-1-INPUT -p 51 -j ACCEPT -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #SSH, HTTP, FTP1, FTP2, MySQL -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport [Port No.] -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT
最後にiptablesの再起動です。これが表示されたらOKです。
[root@localhost ~]# sudo /etc/rc.d/init.d/iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ]
(おまけ)CentOSの日本語化
これもやっておくといいかもしれません。
[root@localhost ~]# sudo vim /etc/sysconfig/i18n
編集内容
LANG="C" → LANG="ja_JP.UTF-8" #日本語・UTF-8に変更
以上です。
参考リンク



コメント