65行目: 65行目:
A [[daemon]] is <u>a service process that runs in the background and supervises the system or provides functionality to other processes</u>. Traditionally, daemons are implemented following a scheme originating in SysV Unix. Modern daemons should follow a simpler yet more powerful scheme (here called "new-style" daemons), as <u>implemented by [[systemd]](1)</u>. This manual page covers both schemes, and in particular includes recommendations for daemons that shall be included in the systemd init system.
A [[daemon]] is <u>a service process that runs in the background and supervises the system or provides functionality to other processes</u>. Traditionally, daemons are implemented following a scheme originating in SysV Unix. Modern daemons should follow a simpler yet more powerful scheme (here called "new-style" daemons), as <u>implemented by [[systemd]](1)</u>. This manual page covers both schemes, and in particular includes recommendations for daemons that shall be included in the systemd init system.


* Debian11でデフォルトで [[稼働しているサービス(Debian系)]]
* Debian11でデフォルトで稼働している [[稼働しているサービス(Debian系)|ユニット]]
* 218個のユニット/部隊が登録されているので稼働部隊の採用/不採用を決定
* 218個のユニット/部隊が登録されているので稼働部隊の採用/不採用を決定
* セキュリティを考慮して使わないサービスは停止、自動稼働も無効にする
* セキュリティを考慮して使わないサービスは停止、自動稼働も無効にする

2023年4月2日 (日) 21:23時点における版

Debian
SimCity

Debian城の「全体」を理解してまとめておく。聖書やSimcityと同じで Debian城も「全体をしっかり把握」していれば、本質を深く理解でき、情報不足ゆえのつまずきを避ける事ができ、管理運営そのものも最高に楽しくなる。システムを「全て把握」していると何事も最高になる!

ちなみに、公開サーバになった「城」はインターネット世界の荒海に広く開かれた「港マシン」となるので全てを把握していた方が城の「運営や防御」が上手にできる。

城の建設/インストール

  • BASH文字化けの恐れがあるので基本的に「英語」でインスト
  • ただし、キーボードは「日本語」で「¥/|」が正しく入力されるか確認

いざ!自分の城へ接続!

環境設定

  • Bash環境は接続元マシンの設定が反映?
$ cat /etc/debian_version 
$ vi .bash_aliases
 alias ls='ls -lh --color=auto'
 alias less='less -N'
$ . ~/.bash_aliases

SSH接続

[管制室]
$ ssh-keygen -t ed25519   秘密鍵(接続元)と公開鍵(サーバ)のペアを作成
$ vi ~/.ssh/config
 HOST hoge
 HostName moge.vs.sakura.ne.jp
 Port 55555
$ ssh-copy-id hoge
$ ssh-add
$ ssh-add -l
$ ssh hoge
[港マシン]
$ systemctl status sshd
$ ss -tan
# vi /etc/ssh/sshd_config
 Port 55555
# systemctl sshd restart
$ ss -tan
$ lsof -i:55555
# ls /etc/ssh
$ ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub   フィンガープリントの確認
# vi /etc/ssh/sshd_config
 PasswordAuthentication no
$ cat ~/.ssh/authorized_keys
  • SSHの鍵認証で最も広く使われているのはRSA暗号。でも最近のSSHはRSAよりも「Ed25519」という暗号化アルゴリズムが強固でパフォーマンスも良く安全面と性能面で最強

城ざっくり把握

以下5点(城の説明書)を把握すれば城の全体像は掴める。

  1. FHS - 城全体の地図
  2. 城内サービス/ダイモン - 住み込み常駐部隊 (30/218部隊)
  3. 城内コマンド/アプリ - 城で働く正社員 (836名)
  4. 城内パッケージ - 城で働く派遣社員 (?)
  5. 城ログ - 城で働く社員たちからの報告レポート

2. 城内サービス/ダイモン(常駐社員)

A daemon is a service process that runs in the background and supervises the system or provides functionality to other processes. Traditionally, daemons are implemented following a scheme originating in SysV Unix. Modern daemons should follow a simpler yet more powerful scheme (here called "new-style" daemons), as implemented by systemd(1). This manual page covers both schemes, and in particular includes recommendations for daemons that shall be included in the systemd init system.

  • Debian11でデフォルトで稼働している ユニット
  • 218個のユニット/部隊が登録されているので稼働部隊の採用/不採用を決定
  • セキュリティを考慮して使わないサービスは停止、自動稼働も無効にする
  • 「running」は常に戦闘モードな状態。一方「exited」は休んでいる状態
# systemctl -t service | grep running
# systemctl stop [service]
# systemctl disable [service]
  • ランレベル3(CUIモード)で自動起動するサービスを確認して停止、自動起動をオフにする
# chkconfig --list | grep 3:on
# service auditd stop
# service netfs stop
auditd(コマンド監視), ip6tables(IP6利用), netfs(NFSクライアント), postfix(SMTPサーバ利用)
  • メールサーバなど、ユーザアカウントは必要だけどシェルログインは不要なユーザは、ログインシェルを「/sbin/nologin」か「/bin/false」にする
#useradd -s /sbin/nologin march
#usermod -s /sbin/nologin march

3. 城内コマンド/アプリ(正社員)

  • Debian11では「sbin - システム管理者用(209個)」と「bin - 一般ユーザ用(627個)」の2種類のコマンドがある
  • とりあえず、上記2種類を把握すればDebianシステムがデフォルトでできる事のおおよそのイメージがつく
  • 「sbin」は一般ユーザからは見えない root用コマンド。rootになる必要がある
  • オプション「--help」や「-V」、「man」でコマンドの解説が見れる
  • ただしiPhoneアプリ等と同じで、深く理解すべきは全体の2割、よく利用されるコマンド (100個程)。故に、無意味な深掘りは厳禁。取捨選択が大切
  • 最後にLinuxコマンドの内容も統合する
lrwxrwxrwx 1 root root 8 Nov 28 14:35 /sbin -> usr/sbin
lrwxrwxrwx 1 root root 7 Nov 28 14:35 /bin -> usr/bin

4. 城内パッケージ(派遣社員)

  • 派遣社員たちはパッケージ管理システム「apt」を使って管理
  • 全てのパッケージを最新のものにアップデートしてシステムを最新の状態にする
$ apt list --installed
# apt update
# apt upgrade
# apt full-upgrade
  • 管理パッケージのアップデートは自動化できる
# apt install cron-apt    ← vi /etc/cron-apt/config(アプデ自動化)
# timedatectl status
# timedatectl set-timezone Asia/Tokyo
# date
  • ユーザがディスクの空き容量を使い切ってしまわないように、ユーザが利用するファイルシステムには独立したパーティションを割り当てる
  • 変更されないデータを格納するファイルシステムは、リードオンリーでマウントすることによりファイルの改竄や破壊行為を抑えられる
  • アドレススキャン(港探索)回避のためにブロードキャスト宛リクエストを無視する。下記の設定ファイルに追記
/etc/sysctl.conf
net.ipv4.icmp_echo_ignore_broadcast=1

5. 城ログ(社員たちからの報告レポート)

城の状態を把握するために必要な現地からのフィードバック。