
Debian の「全体」を理解してまとめておく。聖書と同じで Debian も「全体をしっかり理解」しておけば本質も深く理解できるし、情報不足ゆえのつまずきも少なくなる。
ちなみに、「港マシン」はインターネット世界の荒海に対して公開されてる「港」なので色々なことを深く知っていた方が「港運営」が上手にできる。システムを「全て把握」していると何事もスムーズに運ぶ。
いざ!自分の港へGO!
- 港管理者のチェックリスト / Linuxマシンのセットアップ
- セキュアなDebianサーバを構築する
- Debian はインストール時に root と一般ユーザを登録する
- sudoコマンドがないので「su -」で root になって操作する。root が馴染み深くなる
環境設定
$ cat /etc/debian_version $ vi .bash_aliases alias ls='ls -lh --color=auto' alias less='less -N' $ . ~/.bash_aliases
SSH接続
[港] $ 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-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
- SSHの鍵認証で最も広く使われているのはRSA暗号。でも最近のSSHはRSAよりも「Ed25519」という暗号化アルゴリズムが強固でパフォーマンスも良く安全面と性能面で最強
港ざっくり把握
港の全体像(説明書)は以下4点を把握すれば掴める。
- FHS - 港全体の地図
- 港内サービス - 住み込み常駐社員
- 港内コマンド/アプリ - 港で働く正社員
- 港内パッケージ - 港で働く派遣社員
2. 港内サービス
# systemctl -t service | grep running # systemctl stop [service] # systemctl disable [service]
- 稼働サービスの採用/不採用を決定
- 稼働サービスの確認と停止。セキュリティを考慮して使わないサービスは停止、自動稼働も無効にする
- 「running」は常に戦闘モードな状態。一方「exited」は休んでいる状態
- Debian11では、デフォルトで以下「27個」のサービスが稼働している
daemon | 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. |
---|---|
systemd init |
systemd is a system and service manager for Linux operating systems. When run as first process on boot (as PID 1), it acts as init system that brings up and maintains userspace services. Separate instances are started for logged-in users to start their services. systemd is usually not invoked directly by the user, but is installed as the /sbin/init symlink and started during early boot. The user manager instances are started automatically through the user@.service(5) service. |
runningサービス
cron | Regular background program processing daemon |
---|---|
avahi-daemon | (running) Avahi mDNS/DNS-SD Stack |
bluetooth | (running) Bluetooth service |
console-setup | (exited) Set console font and keymap |
cron | (running) Regular background program |
dbus | (running) D-Bus System Message Bus |
dhcpcd | (running*) dhcpcd on all interfaces |
dphys-swapfile | (exited) LSB: Autogenerate and use |
fake-hwclock | (exited) Restore / save the curren |
getty@tty1 | (running) Getty on tty1 |
hciuart | (running) Configure Bluetooth Modem |
- デフォルトで 稼働しているサービス(Debian系)
- デフォルトで 稼働しているサービス(RH系)
- 不要なサービスは脆弱性の元なので全て停止する。ランレベル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. 港内コマンド/アプリ
lrwxrwxrwx 1 root root 8 Nov 28 14:35 /sbin -> usr/sbin lrwxrwxrwx 1 root root 7 Nov 28 14:35 /bin -> usr/bin
- Debian11では「sbin - システム管理者用(202個)」と「bin - 一般ユーザ用(592個)」の2種類のコマンドがある
- とりあえず、上記2種類を把握すればDebianシステムがデフォルトでできる事のおおよそのイメージがつく
- 「sbin」は一般ユーザからは見えない root用コマンド。rootになる必要がある
- オプション「--help」や「-V」、「man」でコマンドの解説が見れる
- ただしiPhoneアプリ等と同じで、深く理解すべきは全体の2割、よく利用されるコマンド (100個程)。故に、無意味な深掘りは厳禁。取捨選択が大切
- Linuxコマンドも参考に
4. 港内パッケージ管理
- 全てのパッケージを最新のものにアップデートしてシステムを最新の状態にする
$ apt list --installed # apt update # apt upgrade # apt full-upgrade
- 足りない港内アプリはaptパッケージ管理システムからインストールする
- そうすればパッケージを適切に管理できるし、アップデートも自動化できる
# 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