nitta@um580:~/doc/docker/ubuntu24_sshd$ sudo ufw status
[sudo] nitta のパスワード:
状態: アクティブ
To Action From
-- ------ ----
80 ALLOW Anywhere
22 ALLOW Anywhere
443 ALLOW Anywhere
3389 ALLOW Anywhere
container に forwarding するポートを開放する。
nitta@um580:~/doc/docker/ubuntu24_sshd$ sudo ufw allow from 0.0.0.0/0 to any port 10022 proto tcp
ルールを追加しました
nitta@um580:~/doc/docker/ubuntu24_sshd$ sudo ufw allow from 0.0.0.0/0 to any port 10080 proto tcp
ルールを追加しました
nitta@um580:~/doc/docker/ubuntu24_sshd$ sudo ufw allow from 0.0.0.0/0 to any port 10443 proto tcp
ルールを追加しました
nitta@um580:~/doc/docker/ubuntu24_sshd$ sudo ufw status
状態: アクティブ
To Action From
-- ------ ----
80 ALLOW Anywhere
22 ALLOW Anywhere
443 ALLOW Anywhere
3389 ALLOW Anywhere
10022/tcp ALLOW Anywhere
10080/tcp ALLOW Anywhere
10443/tcp ALLOW Anywhere
Container を生成して、起動する。
nitta@um580:~/doc/docker/ubuntu24_sshd$ docker run --name ubuntu24-sshd --restart always -p 10022:22 -p 10080:80 -p 10433:433 -e /home/docker/ubuntu24_nitta -h ubuntu24_nitta -e UNAME=nitta -it ubuntu24_sshd
First run. Setting up ...
Creating group nitta with GID=3000
Creating user nitta with UID=3000, GID=3000
ownership of '/home/nitta' retained as nitta:nitta
No command provided. Starting bash ...
ただちにユーザ nitta のパスワードを変更する。
root@ubuntu24_nitta:/# passwd nitta
New password:
Retype new password:
passwd: password updated successfully
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ebbd998b2086 bridge bridge local
17420af9f271 host host local
557533733a33 macvlan_net macvlan local
a3538f29efc6 none null local
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ebbd998b2086 bridge bridge local
17420af9f271 host host local
557533733a33 macvlan_net macvlan local
a3538f29efc6 none null local
$ docker network ls --no-trunc
NETWORK ID NAME DRIVER SCOPE
ebbd998b20868aea17c1e9f3cd85edb3c7c0ce9181edfe9b308284604275e136 bridge bridge local
17420af9f27199ef5081c56e85910d913c73ae8f3885e48e4ed0b09a06d48016 host host local
557533733a33e84ca9eb665736f6a273414778f30a3e744411596008728b0b2b macvlan_net macvlan local
a3538f29efc60166d3f639d42894eff9f902649036619190011c3a66b262a06a none null local
First run. Setting up ...
Creating group www with GID=2000
Creating user www with UID=2000, GID=2000
info: Adding user `www' to group `sudo' ...
ownership of '/home/www' retained as www:www
No command provided. Starting bash ...
root@74996e43a896:/# 2025-05-25 04:58:18,756 CRIT Supervisor is running as root. Privileges were not dropped because no user is \
specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.
2025-05-25 04:58:18,759 INFO RPC interface 'supervisor' initialized
2025-05-25 04:58:18,759 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2025-05-25 04:58:18,759 INFO supervisord started with pid 41
2025-05-25 04:58:19,763 INFO spawned: 'apache2' with pid 44
2025-05-25 04:58:19,765 INFO spawned: 'cron' with pid 45
2025-05-25 04:58:19,766 INFO spawned: 'php-fpm' with pid 46
2025-05-25 04:58:19,768 INFO spawned: 'sshd' with pid 48
2025-05-25 04:58:20,787 INFO success: apache2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-05-25 04:58:20,788 INFO success: cron entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-05-25 04:58:20,788 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-05-25 04:58:20,788 INFO success: sshd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
# ← Container 内の対話環境 (root 権限の bash) が動く
直ちに ユーザ www のパスワードを変更する。
# passwd www
New password: 新しいパスワード ← 新しいパスワードを入力する(エコーバックされない)
Retype new password: 新しいパスワード ← もう一度新しいパスワードを入力する(エコーバックされない)
# iptables -L
bash: iptables: command not found
# ufw status
bash: ufw: command not found
手動で firewall を設定する。
ufw をインストールする。
# apt update
# apt install -y ufw
ufw を有効化する
# ufw enable
Status: active
# ufw allow from 0.0.0.0/0 to any port 22 proto tcp
Rule added
# ufw allow from 0.0.0.0/0 to any port 80 proto tcp
Rule added
# ufw allow from 0.0.0.0/0 to any port 443 proto tcp
Rule added
外部からのアクセスはデフォルトで禁止にする。
# ufw default deny incoming
ファイアウォールの設定状況を見る
# ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
# a2enmod ssl
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
service apache2 restart
# supervisorctl restart apache2
2025-06-06 15:26:04,195 INFO waiting for apache2 to stop
2025-06-06 15:26:04,204 WARN stopped: apache2 (terminated by SIGTERM)
apache2: stopped
2025-06-06 15:26:04,214 INFO spawned: 'apache2' with pid 1418
2025-06-06 15:26:04,257 WARN exited: apache2 (exit status 0; not expected)
2025-06-06 15:26:05,261 INFO spawned: 'apache2' with pid 1421
2025-06-06 15:26:07,227 INFO success: apache2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
apache2: started