VPSのセットアップ

さくらのVPSでUbuntu 14.04 LTSをセットアップしたメモ。

鍵認証の設定

$ ssh-keygen -t rsa -f vps_id_rsa -C "VPS key"
$ scp vps_id_rsa.pub username@xxx.xxx.xxx.xxx:~

鍵を生成して、SCPで転送する。

$ mkdir ~/.ssh
$ chmod 0700 ~/.ssh
$ cat vps_id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys
$ rm vps_id_rsa.pub

これで鍵の設定は出来たはず。

$ sudo cp /etc/ssh/sshd_config{,.bak}

設定ファイルのバックアップを取る。

--- /etc/ssh/sshd_config.bak    2014-09-28 19:40:51.157856850 +0900
+++ /etc/ssh/sshd_config    2014-09-28 19:42:03.024953437 +0900
@@ -2,7 +2,7 @@
 # See the sshd_config(5) manpage for details

 # What ports, IPs and protocols we listen for
-Port 22
+Port 10022
 # Use these options to restrict which interfaces/protocols sshd will bind to
 #ListenAddress ::
 #ListenAddress 0.0.0.0
@@ -25,7 +25,7 @@

 # Authentication:
 LoginGraceTime 120
-PermitRootLogin without-password
+PermitRootLogin no
 StrictModes yes

 RSAAuthentication yes
@@ -49,7 +49,7 @@
 ChallengeResponseAuthentication no

 # Change to no to disable tunnelled clear text passwords
-#PasswordAuthentication yes
+PasswordAuthentication no

 # Kerberos options
 #KerberosAuthentication no

SSHの設定を変更する。実際のポート番号は違うけども。

$ sudo service ssh restart

設定を変更したので、反映させるためにSSHを再起動する。

ファイアーウォールの設定

$ sudo ufw default reject incoming
$ sudo ufw default allow outgoing
$ sudo ufw limit 10022/tcp
$ sudo ufw allow http/tcp
$ sudo ufw enable
$ sudo ufw status verbose

SSHをリミット付きで空けて、HTTPだけ空ける。allow outgoingでいいのかなあとは思いつつも……これで。

アプリケーションのインストール

$ sudo apt-get install ntp sysv-rc-conf

適当にインストールする。

NTPの設定

$ sudo cp /etc/ntp.conf{,.bak}

これもバックアップを取っておく。

--- /etc/ntp.conf.bak   2014-09-28 20:34:36.907270257 +0900
+++ /etc/ntp.conf   2014-09-28 20:36:07.682158447 +0900
@@ -13,6 +13,12 @@

 # Specify one or more NTP servers.

+server ntp.nict.jp
+server ntp1.jst.mfeed.ad.jp
+server ntp2.jst.mfeed.ad.jp
+server ntp3.jst.mfeed.ad.jp
+server ntp.ring.gr.jp
+
 # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
 # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
 # more information.

国内のNTPサーバを指定させてもらう。

コンソールの設定

$ sudo cp /etc/default/console-setup{,.bak}

これもバックアップを取っておく。

--- /etc/default/console-setup.bak  2014-09-28 20:04:50.530356605 +0900
+++ /etc/default/console-setup  2014-09-28 20:05:06.102133417 +0900
@@ -2,7 +2,7 @@
 VERBOSE_OUTPUT="no"

 # Setup these consoles.  Most people do not need to change this.
-ACTIVE_CONSOLES="/dev/tty[1-6]"
+ACTIVE_CONSOLES="/dev/tty[1-2]"

 # Put here your encoding.  Valid charmaps are: UTF-8 ARMSCII-8 CP1251
 # CP1255 CP1256 GEORGIAN-ACADEMY GEORGIAN-PS IBM1133 ISIRI-3342

コンソールを6個も使わないので2個にする。

$ cd /etc/init
$ for i in `seq 3 6`
> do
>   sudo sed -i.bak 's/^/#/' tty${i}.conf
> done

3から6までのttyが起動しないようにする。


基本的な設定はこれで終わり。

この辺、全部Dockerで扱えるようにしてDockerfileで管理すればこういうのも必要なくなるんだろうなあ。