LoginSignup
396
477

More than 3 years have passed since last update.

Ubuntu 最低限抑えておきたい初期設定

Last updated at Posted at 2016-02-22

hostname の設定

$ sudo hostnamectl set-hostname <hostname>

パッケージリストの更新

$ sudo apt-get update

インストールされてるパッケージの更新

$ sudo apt-get upgrade

パッケージ自動アップデート

unattended-upgrades のインストール

$ sudo apt-get install unattended-upgrades

自動アップデートの適用

<Yes> を選択し設定することが可能です。

$ sudo dpkg-reconfigure -plow unattended-upgrades

Creating config file /etc/apt/apt.conf.d/20auto-upgrades with new version

自動アップデートの設定

設定項目

項目 意味
security 重要なセキュリティーアップデート
updates 奨励アップデート
proposed プレリリースされたアップデート
backports サポートされていないアップデート

セキュリティーアップデートと奨励アップデートの自動設定

/etc/apt/apt.conf.d/50unattended-upgrades
    // Automatically upgrade packages from these (origin:archive) pairs
    Unattended-Upgrade::Allowed-Origins {
            "${distro_id}:${distro_codename}-security";
-   //      "${distro_id}:${distro_codename}-updates";
+           "${distro_id}:${distro_codename}-updates";
    //      "${distro_id}:${distro_codename}-proposed";
    //      "${distro_id}:${distro_codename}-backports";
    };

sshd の設定

ポートの変更

/etc/ssh/sshd_config
    # What ports, IPs and protocols we listen for
-   Port 22
+   Port 2222

root ログインを禁止

/etc/ssh/sshd_config
    # Authentication:
    LoginGraceTime 120
-   PermitRootLogin without-password
+   PermitRootLogin no
    StrictModes yes

パスワード認証を禁止

/etc/ssh/sshd_config
    # Change to no to disable tunnelled clear text passwords
-   PasswordAuthentication yes
+   PasswordAuthentication no

PAM認証を禁止

/etc/ssh/sshd_config
    # Set this to 'yes' to enable PAM authentication, account processing,
    # and session processing. If this is enabled, PAM authentication will
    # be allowed through the ChallengeResponseAuthentication and
    # PasswordAuthentication.  Depending on your PAM configuration,
    # PAM authentication via ChallengeResponseAuthentication may bypass
    # the setting of "PermitRootLogin without-password".
    # If you just want the PAM account and session checks to run without
    # PAM authentication, then enable this but set PasswordAuthentication
    # and ChallengeResponseAuthentication to 'no'.
-   UsePAM yes
+   UsePAM no

ssh サービスの再起動

$ sudo service ssh restart

ファイアウォールの設定

ufw のインストール

$ sudo apt-get install ufw

ufw の設定

IPv6サポートのOFF

/etc/default/ufw
    # Set to yes to apply rules to support IPv6 (no means only IPv6 on loopback
    # accepted). You will need to 'disable' and then 'enable' the firewall for
    # the changes to take affect.
-   IPV6=yes
+   IPV6=no

ポートの開放

ssh
$ sudo ufw allow 2222
http
$ sudo ufw allow 80
https
$ sudo ufw allow 443

許可されたポート以外全ての閉鎖

$ sudo ufw default deny

ufw の有効化

$ sudo ufw enable

確認

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
2222/tcp                   ALLOW       Anywhere
443                        ALLOW       Anywhere

locale の設定

language-pack-ja のインストール

$ sudo apt-get install language-pack-ja

locale に ja_JP.UTF-8 を設定

$ sudo update-locale LANG=ja_JP.UTF-8

確認

$ strings /etc/default/locale
# Created by cloud-init v. 0.7.5 on Tue, 16 Feb 2016 06:41:26 +0000
LANG=ja_JP.UTF-8

timezone の設定

/usr/share/zoneinfo/Asia/Tokyo から /etc/localtime にリンクを張る

$ sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

timezone に Asia/Tokyo を設定

dpkg-reconfigure tzdata コマンドを実行し、インタラクティブウィンドウから timezone を選択し設定することが可能です。
Ansible など、構成管理ツールで設定する際はノンインタラクティブでないと実行できません。
下記のように、 dpkg-reconfigure tzdata コマンドに --frontend noninteractive オプションを付けことでノンインタラクティブに実行出来ます。

$ sudo dpkg-reconfigure --frontend noninteractive tzdata

Current default time zone: 'Asia/Tokyo'
Local time is now:      Tue Feb 16 15:47:47 JST 2016.
Universal Time is now:  Tue Feb 16 06:47:47 UTC 2016.

確認

$ strings /etc/localtime
TZif2
        JCST
TZif2
JCST
JST-9

フォントの設定

ipafont 一式のインストール

$ sudo apt-get install fonts-ipafont

確認

truetype ディレクトリが存在することを確認します。

$ ls /usr/share/fonts/
X11  truetype

時刻の設定

ntp のインストール

$ sudo apt-get install ntp

ntp サービスの停止

時刻を取得するために ntp を停止します。

$ sudo service ntp stop
 * Stopping NTP server ntpd
   ...done.

時刻を他サーバから取得する

日本標準時を時刻配信している ntp サーバ ( ntp.nict.jp ) から時刻を取得します。

$ sudo ntpdate ntp.nict.jp
16 Feb 17:03:22 ntpdate[6848]: adjust time server 133.243.238.244 offset -0.085880 sec

時刻の自動同期の設定

/etc/ntp.conf
    # Specify one or more NTP servers.

    # 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.
-   server 0.ubuntu.pool.ntp.org
-   server 1.ubuntu.pool.ntp.org
-   server 2.ubuntu.pool.ntp.org
-   server 3.ubuntu.pool.ntp.org
+   server -4 ntp.nict.jp
+   server -4 ntp1.jst.mfeed.ad.jp
+   server -4 ntp2.jst.mfeed.ad.jp
+   server -4 ntp3.jst.mfeed.ad.jp

ntp サービスの起動

$ sudo service ntp start
 * Starting NTP server ntpd
   ...done.

サービス自動起動の設定

sysv-rc-conf のインストール

sysv-rc-conf は簡単に説明すると chkconfig の代わりとなるものです。

$ sudo apt-get install sysv-rc-conf

sysv-rc-conf で ntp サービス自動起動の設定

$ sudo sysv-rc-conf ntp on

確認

$ sudo sysv-rc-conf --list ntp
ntp          1:off      2:on    3:on    4:on    5:on

OS の再起動

$ sudo reboot

追記

これやってるなと思い出したものがあれば随時更新していきます。
本記事の内容を Ansible の Playbook に落としている最中なので完成したら公開します。

396
477
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
396
477