自分用・検証用 Ubuntu22.04.2LTS 作成手順メモ(2023/06/05 版)

以前に以下のメモを書きました。

現時点では Ubuntu 22.04.2LTS までリリースされていますので、改めて検証用 Ubuntu の作成手順をメモにしておきます。

  1. 変更点
  2. Ubuntu の ISO イメージ
  3. コンソールからインストーラへアクセスする
  4. 仮想マシンのスペック
  5. インストール
    1. Step.1 Willkommen! Bienvenue! Welcome! Добро пожаловать! Welkom
    2. Step.2 Installer update available
    3. Step.3 Keyboard configuration
    4. Step.4 Choose type of install
    5. Step.5 Network connections
    6. Step.6 Configure proxy
    7. Step.7 Configure Ubuntu archive mirror
    8. Step.8 Guided storage configuration
    9. Step.9 Profile setup
    10. Step.10 Upgrade to Ubuntu Pro
    11. Step.11 SSH Setup
    12. Step.12 Featured Server Snaps
    13. Step.13 Install complete!
  6. 初期セットアップ
    1. Step.A 標準ユーザで SSH ログインする
    2. Step.B sshd の設定変更 (自動切断の防止 / root ログインの許可)
    3. Step.C root のパスワードを設定する
    4. Step.D root ユーザの公開鍵を登録する
    5. Step.E 標準ユーザを削除する
    6. Step.F AppArmor を無効化する
    7. Step.G システム全体のアップデート
    8. Step.H SSH 接続時の警告時を表示しない
    9. Step.I タイムゾーンを Asia/Tokyo に設定する
    10. Step.J NTP の時刻同期先サーバを設定する
    11. Step.K プロンプト表示をカスタマイズする
    12. Step.L Welcome メッセージを表示しない
    13. Step.M コンソールの有効化
      1. 変更前 (コメント除外版)
      2. 変更後
    14. Step.N アドレス変更用スクリプトを配置する
    15. Step.O パッケージのインストール
      1. 基本的なパッケージ
      2. pip と venv
      3. direnv
      4. uncmnt
      5. docker
      6. docker compose
      7. docker purge
    16. Step.P キャッシュ / コマンド実行履歴を削除して仮想マシンを停止する
    17. Step.Q VM から DVD メディアを取り出しておく
    18. Step.R テンプレート化する

変更点

内容は過去メモとほぼ同じですが、以下が異なります。

  • インストールするツールのバージョンを現時点の最新版へ変更
  • インストールするツールに ripgrep を追加

Ubuntu の ISO イメージ

Ubuntu の ISO イメージは IIJ が公開しているページ からダウンロードします。 今回は ubuntu-22.04.2-live-server-amd64.iso を利用しました。

コンソールからインストーラへアクセスする

必要になる場合は少ないと思われますが、コンソールからインストーラへアクセスしたい場合は VM の Ubuntu でコンソールからインストーラへ接続する を参考にします。

仮想マシンのスペック

今回、作成する仮想マシンのスペックは以下としました。 デフォルトでは LVM が利用されますが、ストレージを 10GB 以上にすると / にマウントされるのが (最大サイズでは無く) 10GB しか割り当てられません。 今回は / に最大サイズを割り当てたい為、インストール中に調整します。

項目
vCPU 4
Memory 4GB
Storage 50GB

インストールイメージは以下を利用しました。

インストール

Step.1 Willkommen! Bienvenue! Welcome! Добро пожаловать! Welkom

言語を選択します。 English を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Willkommen! Bienvenue! Welcome! Добро пожаловать! Welkom!           [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Use UP, DOWN and ENTER keys to select your language.

                [ Asturianu                                 ▸ ]▴
                [ Bahasa Indonesia                          ▸ ]█
                [ Català                                    ▸ ]
                [ Deutsch                                   ▸ ]
                [ English                                   ▸ ]
                [ English (UK)                              ▸ ]
                [ Español                                   ▸ ]
                [ Français                                  ▸ ]
                [ Galego                                    ▸ ]
                [ Hrvatski                                  ▸ ]
                [ Latviski                                  ▸ ]
                [ Lietuviškai                               ▸ ]
                [ Magyar                                    ▸ ]
                [ Nederlands                                ▸ ]
                [ Norsk bokmål                              ▸ ]
                [ Occitan (aprèp 1500)                      ▸ ]▾

                                 [ Back       ]

Step.2 Installer update available

新しいインストーラを利用するか、選択を求められます。 Continue without updating を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Installer update available                                          [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Version 23.04.2 of the installer is now available (23.02.1 is currently
  running).

  You can read the release notes for each version at:

                 https://github.com/canonical/subiquity/releases

  If you choose to update, the update will be downloaded and the installation
  will continue from here.

                        [ Update to the new installer ]
                        [ Continue without updating   ]
                        [ Back                        ]

Step.3 Keyboard configuration

キーボードの設定を行います。 Layout と Variant は両方 English (US) を選択して次に進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Keyboard configuration                                              [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Please select the layout of the keyboard directly attached to the system, if
  any.

                 Layout:  [ English (US)                     ▾ ]

                Variant:  [ English (US)                     ▾ ]

                                 [ Done       ]
                                 [ Back       ]

Step.4 Choose type of install

インストール種別を選択します。 Ubuntu Server を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Choose type of install                                              [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Choose the base for the installation.

  (X)  Ubuntu Server                                                         ▴
                                                                             █
       The default install contains a curated set of packages that provide a █
       comfortable experience for operating your server.                     █
                                                                             █
  ( )  Ubuntu Server (minimized)                                             █
                                                                             █
       This version has been customized to have a small runtime footprint in █
       environments where humans are not expected to log in.                 █
                                                                             █
  Additional options                                                         █
                                                                             █
  [ ]  Search for third-party drivers

       This software is subject to license terms included with its           ▾

                                 [ Done       ]
                                 [ Back       ]

Step.5 Network connections

ネットワーク設定を行います。 環境に合わせて設定したら次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Network connections                                                 [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Configure at least one interface this server can use to talk to other
  machines, and which preferably provides sufficient access for updates.

    NAME    TYPE  NOTES
  [ ens160  eth   -                ▸ ]
    DHCPv4  10.0.0.100/24
    00:50:56:b6:03:d1 / VMware / VMXNET3 Ethernet Controller

  [ Create bond ▸ ]

                                 [ Done       ]
                                 [ Back       ]

Step.6 Configure proxy

Proxy の設定を行います。 Proxy は利用しない想定なので空欄のまま、次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Configure proxy                                                     [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  If this system requires a proxy to connect to the internet, enter its
  details here.

  Proxy address:
                  If you need to use a HTTP proxy to access the outside world,
                  enter the proxy information here. Otherwise, leave this
                  blank.

                  The proxy information should be given in the standard form
                  of "http://[[user][:pass]@]host[:port]/".

                                 [ Done       ]
                                 [ Back       ]

Step.7 Configure Ubuntu archive mirror

ミラーの URL を指定します。 http://jp.archive.ubuntu.com/ubuntu のままで次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Configure Ubuntu archive mirror                                     [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  If you use an alternative mirror for Ubuntu, enter its details here.

  Mirror address:  http://jp.archive.ubuntu.com/ubuntu
                   You may provide an archive mirror that will be used instead
                   of the default.

                                 [ Done       ]
                                 [ Back       ]

Step.8 Guided storage configuration

ストレージ領域の設定を行います。 デフォルトで Use an entire disk が選択されているので、このまま Done を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Guided storage configuration                                        [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Configure a guided storage layout, or create a custom one:

  (X)  Use an entire disk

       [ /dev/sda local disk 50.000G ▾ ]

       [X]  Set up this disk as an LVM group

            [ ]  Encrypt the LVM group with LUKS

                         Passphrase:

                 Confirm passphrase:

  ( )  Custom storage layout

                                 [ Done       ]
                                 [ Back       ]

以下のような画面が表示されます。 下へスクロールします。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Storage configuration                                               [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  FILE SYSTEM SUMMARY                                                        ▴
                                                                             █
    MOUNT POINT     SIZE    TYPE      DEVICE TYPE                            █
  [ /              23.996G  new ext4  new LVM logical volume      ▸ ]        █
  [ /boot           2.000G  new ext4  new partition of local disk ▸ ]        █
                                                                             █
                                                                             █
  AVAILABLE DEVICES                                                          █
                                                                             █
    DEVICE                                   TYPE                 SIZE
  [ ubuntu-vg (new)                          LVM volume group    47.996G  ▸ ]
    free space                                                   24.000G  ▸

  [ Create software RAID (md) ▸ ]
  [ Create volume group (LVM) ▸ ]
                                                                             ▾

                                 [ Done       ]
                                 [ Reset      ]
                                 [ Back       ]

ubuntu-lv を選択し、サイズを最大へ修正しておきます。 修正が完了したら Done を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Storage configuration                                               [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
                                                                             ▴
  [ Create software RAID (md) ▸ ]
  [ Create volume group (LVM) ▸ ]

  USED DEVICES

    DEVICE                                   TYPE                 SIZE       █
  [ ubuntu-vg (new)                          LVM volume group    47.996G  ▸ ]█
    ubuntu-lv    new, to be formatted as ext4, mounted at /      23.996G  ▸  █
                                                                             █
  [ /dev/sda                                 local disk          50.000G  ▸ ]█
    partition 1  new, BIOS grub spacer                            1.000M  ▸  █
    partition 2  new, to be formatted as ext4, mounted at         2.000G  ▸  █
                 /boot                                                       █
    partition 3  new, PV of LVM volume group ubuntu-vg           47.997G  ▸  ▾

                                 [ Done       ]
                                 [ Reset      ]
                                 [ Back       ]

続行の確認を求められます。 Continue を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Storage configuration                                               [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  [ Create software RAID (md) ▸ ]                                            ▴
  [ Create volume group (LVM) ▸ ]

   ┌────────────────────── Confirm destructive action ──────────────────────┐
   │                                                                        │
   │  Selecting Continue below will begin the installation process and      │
   │  result in the loss of data on the disks selected to be formatted.     │
   │                                                                        │
   │  You will not be able to return to this or a previous screen once the  │
   │  installation has started.                                             │
   │                                                                        │
   │  Are you sure you want to continue?                                    │
   │                                                                        │
   │                             [ No         ]                             │
   │                             [ Continue   ]                             │
   │                                                                        │
   └────────────────────────────────────────────────────────────────────────┘

                                 [ Reset      ]
                                 [ Back       ]

Step.9 Profile setup

追加するユーザのプロファイル情報を入力します。 スキップ出来ず、しかも全項目入力必須なようです。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Profile setup                                                       [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Enter the username and password you will use to log in to the system. You
  can configure SSH access on the next screen but a password is still needed
  for sudo.

              Your name:

     Your server's name:
                          The name it uses when it talks to other computers.

        Pick a username:

      Choose a password:

  Confirm your password:

                                 [ Done       ]

今回は以下のように入力しました。 入力が完了したら Done を選択して続行します。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Profile setup                                                       [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Enter the username and password you will use to log in to the system. You
  can configure SSH access on the next screen but a password is still needed
  for sudo.

              Your name:  user

     Your server's name:  localhost
                          The name it uses when it talks to other computers.

        Pick a username:  user

      Choose a password:  *********

  Confirm your password:  *********

                                 [ Done       ]

Step.10 Upgrade to Ubuntu Pro

Ubuntu Pro へアップグレードするか、確認されます。 Skip for now が選択された状態で Continue を選択し、次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Upgrade to Ubuntu Pro                                               [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  Upgrade this machine to Ubuntu Pro for security updates on a much wider
  range of packages, until 2032. Assists with FedRAMP, FIPS, STIG, HIPAA and
  other compliance or hardening requirements.

  [ About Ubuntu Pro ▸ ]

  ( )  Enable Ubuntu Pro

  (X)  Skip for now

       You can always enable Ubuntu Pro later via the 'pro attach' command.

                                 [ Continue   ]
                                 [ Back       ]

Step.11 SSH Setup

OpenSSH サーバをインストールするか、選択を要求されます。 デフォルトでは「インストールしない」状態になっていますので、Install OpenSSH server にチェックを入れ、Done を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  SSH Setup                                                           [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  You can choose to install the OpenSSH server package to enable secure remote
  access to your server.

                   [ ]  Install OpenSSH server

  Import SSH identity:  [ No             ▾ ]
                        You can import your SSH keys from GitHub or Launchpad.

      Import Username:

                   [X]  Allow password authentication over SSH

                                 [ Done       ]
                                 [ Back       ]

Step.12 Featured Server Snaps

インストールするソフトウェアを選択します。 必要なものは後からインストールしますので、ここでは何もせず、Done を選択して次へ進みます。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Featured Server Snaps                                               [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  These are popular snaps in server environments. Select or deselect with
  SPACE, press ENTER to see more details of the package, publisher and
  versions available.

  [ ] microk8s            Kubernetes for workstations and appliances        ▸▴
  [ ] nextcloud           Nextcloud Server - A safe home for all your data  ▸█
  [ ] wekan               The open-source kanban                            ▸█
  [ ] kata-containers     Build lightweight VMs that seamlessly plug into t ▸█
  [ ] docker              Docker container runtime                          ▸█
  [ ] canonical-livepatch Canonical Livepatch Client                        ▸█
  [ ] rocketchat-server   Rocket.Chat server                                ▸█
  [ ] mosquitto           Eclipse Mosquitto MQTT broker                     ▸
  [ ] etcd                Resilient key-value store by CoreOS               ▸
  [ ] powershell          PowerShell for every system!                      ▸
  [ ] stress-ng           tool to load and stress a computer                ▸
  [ ] sabnzbd             SABnzbd                                           ▸
  [ ] wormhole            get things from one computer to another, safely   ▸▾

                                 [ Done       ]
                                 [ Back       ]

Step.13 Install complete!

インストールが完了後、ネットワークに接続されている場合はアップデートが開始されます。 なぜか毎回、このアップデートが完了しない (時間がかかる?) 為、Cancel update and reboot を選択して再起動します。

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  Install complete!                                                   [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  ┌──────────────────────────────────────────────────────────────────────────┐
  │            apply networking config                                      ▴│
  │            writing etc/fstab                                             │
  │            configuring multipath                                         │
  │            updating packages on target system                            │
  │            configuring pollinate user-agent on target                    │
  │            updating initramfs configuration                              │
  │            configuring target system bootloader                          │
  │            installing grub to target devices                             │
  │final system configuration                                                │
  │  configuring cloud-init                                                  │
  │  calculating extra packages to install                                   │
  │  installing openssh-server                                               │
  │    curtin command system-install                                         │
  │  downloading and installing security updates                            █│
  │    curtin command in-target -                                           ▾│
  └──────────────────────────────────────────────────────────────────────────┘

                          [ View full log            ]
                          [ Cancel update and reboot ]

初期セットアップ

Step.A 標準ユーザで SSH ログインする

追加パッケージをインストールしなくても open-vm-tools がインストールされる為、vSphere 上から作成した仮想マシンの IP アドレスが分かるはずです。 この IP アドレスに対して、インストール中に作成したユーザで SSH ログインします。

$ ssh user@10.0.0.100
Warning: Permanently added '10.0.0.100' (ECDSA) to the list of known hosts.
user@10.0.0.100's password:
Welcome to Ubuntu Jammy Jellyfish (development branch) (GNU/Linux 5.15.0-25-generic x86_64)
(snip)
user@localhost:~$

以降の作業を実施する為に root ユーザになっておきます。

user@localhost:~$ sudo su -
[sudo] password for user:
root@localhost:~#

Step.B sshd の設定変更 (自動切断の防止 / root ログインの許可)

sshd で自動切断されるのを防ぐ為、ClientAliveInterval や ClientAliveCountMax を設定します。 これらの値は以下の意味を持ちます。

項目 意味 デフォルト値
ClientAliveInterval 指定した秒数ごとに応答確認を行う間隔 (※ 0 の場合は何もしない) 0
ClientAliveCountMax 応答確認を行う回数 3

これらの値をチューニングしつつ、root ユーザでの SSH ログインを許可しておきます。 設定が完了したら sshd を再起動しておきます。

sed -i -e "s/#ClientAliveInterval 0/ClientAliveInterval 60/g" /etc/ssh/sshd_config && \
sed -i -e "s/#ClientAliveCountMax 3/ClientAliveCountMax 5/g" /etc/ssh/sshd_config && \
sed -i -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
systemctl restart sshd.service

sshd の設定確認には sshd -T を実行します。

sshd -T

Step.C root のパスワードを設定する

root ユーザのパスワードを変更しておきます。 パスワードは自身の環境に合わせて任意で設定します。

echo root:'PASSWORD' | /usr/sbin/chpasswd

パスワード変更後は root ユーザを指定し、パスワード認証による SSH ログインが出来ることを確認しておきます。 以降の作業は (標準ユーザはログアウトし) root ユーザで継続します。

Step.D root ユーザの公開鍵を登録する

root ユーザへ鍵を使って SSH ログイン出来るよう、公開鍵を登録しておきます。 鍵の登録が終わったら、実際に鍵を使って (パスワードを入力せずに) SSH ログイン出来ることを確認します。

cat << 'EOS' >> ~/.ssh/authorized_keys
(公開鍵)
EOS
chmod 600 ~/.ssh/authorized_keys

Step.E 標準ユーザを削除する

一般的にはセキュリティの観点から推奨されませんが、「標準ユーザは不要」「検証環境なので全て root で作業する」と割り切れるのであれば、インストール中に作成した標準ユーザを削除します。

userdel -r user

Step.F AppArmor を無効化する

AppArmor は RedHat 系で言うところの SELinux に近いセキュリティ機構です。 デフォルトでは有効化されている為、無効化しておきます。

systemctl stop apparmor.service
systemctl disable apparmor.service

Step.G システム全体のアップデート

システム全体のアップデートを実行します。 カーネルの更新などがある場合を考慮し、アップデート後は OS を再起動します。

apt -y update && \
apt -y upgrade && \
reboot

Step.H SSH 接続時の警告時を表示しない

別のホストへ SSH 接続する際、警告が表示されないように設定しておきます。 また Unable to negotiate with 192.168.1.1 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 等のエラーを回避する為に、必要な鍵交換アルゴリズムを追加しておきます。

cat << EOF > /etc/ssh/ssh_config.d/99_lab.conf
Ciphers aes128-cbc,aes256-ctr
HostkeyAlgorithms +ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF

Step.I タイムゾーンを Asia/Tokyo に設定する

タイムゾーンを Asia/Tokyo に設定しておきます。 設定が完了したら datetimedatectl status でタイムゾーンが Asia/Tokyo へ変更されたことを確認しておきます。

timedatectl set-timezone Asia/Tokyo

Step.J NTP の時刻同期先サーバを設定する

NTP サーバは time.cloudflare.com のご紹介 で言及されている CloudFlare の NTP サーバを設定します。

cat << EOF >> /etc/systemd/timesyncd.conf
NTP=162.159.200.123 162.159.200.1
EOF
systemctl restart systemd-timesyncd.service

NTP サーバとの時刻同期状態は timedatectl timesync-status で確認出来ます。

timedatectl timesync-status

Step.K プロンプト表示をカスタマイズする

RedHat / Ubuntu でシェルのプロンプト表示をカスタマイズする というメモを書きましたが、root ユーザのプロンプト表示と今後、新規作成されるユーザ用の設定を実施しておきます。

cat << 'EOF' >> ~/.bashrc

# Modify the prompt.
if [ `id -u` = 0 ]; then
    PS1="[\[\033[1;31m\]\u@\h\[\033[00m\] \W]\\$ "
else
    PS1="[\[\033[1;36m\]\u@\h\[\033[00m\] \W]\\$ "
fi
EOF
cat << 'EOF' >> /etc/skel/.bashrc

# Modify the prompt.
if [ `id -u` = 0 ]; then
    PS1="[\[\033[1;31m\]\u@\h\[\033[00m\] \W]\\$ "
else
    PS1="[\[\033[1;36m\]\u@\h\[\033[00m\] \W]\\$ "
fi
EOF

Step.L Welcome メッセージを表示しない

Ubuntu 21.04 で Welcome メッセージを表示しない というメモを書きましたが、Ubuntu へ SSH ログインした際に表示される Welcome メッセージを表示されないように設定しておきます。

cat << EOF > ~/.hushlogin
exit
EOF

Step.M コンソールの有効化

コンソールを有効化します。 /etc/default/grub を以下のように変更します。


変更前 (コメント除外版)

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

変更後

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,115200n8"
GRUB_CMDLINE_LINUX=""

変更が完了したら update-grub を実行して GRUB を更新しておきます。

update-grub

Step.N アドレス変更用スクリプトを配置する

IP アドレスとゲートウェイ設定を変更するスクリプトを /usr/local/bin/chaddr へ配置します。

cat << EOF > /usr/local/bin/chaddr
#!/usr/bin/env python3
import argparse
import subprocess
import textwrap

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--address', required=True)
parser.add_argument('-g', '--gateway', required=True)
args = parser.parse_args()

hostname = args.address.replace('.', '-')
subprocess.call('hostnamectl set-hostname ' + hostname, shell=True)

netplan = textwrap.dedent('''
network:
  ethernets:
    ens160:
      dhcp4: false
      dhcp6: false
      addresses: [{arg1}/24]
      gateway4: {arg2}
      nameservers:
        addresses: [1.1.1.1, 1.0.0.1]
  version: 2
''').format(arg1=args.address, arg2=args.gateway).strip()

with open('/etc/netplan/99_config.yaml', 'w') as f:
    f.write(netplan)

hosts = textwrap.dedent('''
127.0.0.1 localhost {arg1}
127.0.1.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet {arg1}
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
''').format(arg1=hostname).strip()

with open('/etc/hosts', 'w') as f:
    f.write(hosts)
EOF
chmod 755 /usr/local/bin/chaddr

Step.O パッケージのインストール

パッケージをインストールしておきます。

基本的なパッケージ

基本的なパッケージをインストールしておきます。

apt -y install \
    fping \
    nmap \
    ripgrep \
    tree \
    tshark \
    unzip \
    zip

pip と venv

Ubuntu 22.04.1LST には現時点で python が無く、python3 として Python 3.10.6 がインストールされていました。

# python --version
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3
# python3 --version
Python 3.10.6

しかし、pip と venv が無い為、インストールしておきます。

apt -y install python3-pip python3.10-venv

direnv

Python の venv 環境を direnv で自動的に有効/無効化する というメモを書きましたが、Python で venv を利用しているのであれば direnv が便利です。

curl -L https://github.com/direnv/direnv/releases/download/v2.32.3/direnv.linux-amd64 -o /usr/local/bin/direnv && \
chmod 755 /usr/local/bin/direnv

~/.bashrc にフックして direnv を起動する設定を追加しておきます。

cat << 'EOF' >> ~/.bashrc
# direnv
export EDITOR=vim
eval "$(direnv hook bash)"
EOF

uncmnt

コメントを除外することが出来るツールです。 GitHub の sig9org/uncmnt からインストールしておきます。

curl -L https://github.com/sig9org/uncmnt/releases/download/v0.0.2/uncmnt_v0.0.2_linux_amd64 -o /usr/local/bin/uncmnt && \
chmod 755 /usr/local/bin/uncmnt

docker

docker インストール後は「停止している」ものの「自動起動する」設定になっていました。 念の為、「起動」「自動起動」両方の設定を実施しておきます。

apt-get -y remove docker docker-engine docker.io containerd runc
apt-get update
apt-get -y install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

docker compose

Docker Compose v2 をインストールするには以下を実行します。

mkdir -p /usr/local/lib/docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

docker purge

全コンテナを停止・削除する docker サブコマンド「docker purge」 というメモを書きました。 docker コンテナを一度に停止することが出来るので GitHub の sig9org/docker-purge からインストールしておきます。

mkdir -p /usr/local/lib/docker/cli-plugins/ && \
curl -SL \
  https://github.com/sig9org/docker-purge/releases/download/v0.0.1/docker-purge_v0.0.1_linux_amd64 \
  -o /usr/local/lib/docker/cli-plugins/docker-purge && \
chmod +x /usr/local/lib/docker/cli-plugins/docker-purge

Step.P キャッシュ / コマンド実行履歴を削除して仮想マシンを停止する

apt のキャッシュとコマンド実行履歴を削除しておきます。 ここまで完了したら仮想マシンを電源オフします。

apt -y autoremove && \
apt clean all && \
history -c && \
poweroff

Step.Q VM から DVD メディアを取り出しておく

通常であればインストーラ終了時に光学ドライブからメディアは取り出されているはずですが、万一メディアが残っているようであればテンプレート化する前に取り出しておきます。

Step.R テンプレート化する

ここまで用意が出来たら仮想マシンをテンプレート化します。 以降、検証用の仮想マシンを作成したい場合はこのテンプレートから複製します。

コメント

タイトルとURLをコピーしました