kledgeb UbuntuやLinuxの最新情報を紹介

Ubuntu 22.10 その15 - sshd(OpenSSH)が接続を要求されるまで起動しないように変更・変更によるユーザーへの影響

sshdが接続を要求されるまで起動しないように変更

「Ubuntu 22.10」では「sshd(OpenSSH/openssh-server)」が接続を要求されるまで起動しないように振る舞いが変更されました。
これにより一部の設定が従来から変更されています。


  • SSHd now uses socket-based activation (Ubuntu 22.10 and later)

メモリー消費量削減のため

今回の仕様変更は、「Ubuntu Server」のインスタンスで使用されるメモリー使用量を削減するために行われた変更です。
メモリー使用量の削減は特に仮想マシンやLXDといった環境で重要な取り組みであり、「sshd」が利用されていない状態では「sshd」の分だけメモリー消費量を抑えることができます。
これによりユーザーのハードウェア及びクラウドの活用効率を上げることができます。

デフォルトで「sshd」を起動しないように変更することで、各インスタンスで少なくとも3MiB以上のメモリー使用量を抑えることができ、「Ubuntu 22.10」のコンテナーでは約5%の削減にあたります。

LXDイメージでのメモリー使用の変化

仕様変更前の「Ubuntu 22.04 LTS」のLXDイメージでは、65MiBのメモリーを使用していました。
しかし仕様変更後の「Ubuntu 22.10」では、メモリー使用量が58MiBに改善されています。

今後も改善作業が続く

本件に限らず現在も改善作業が続けられており、将来的に本件も「Ubuntu 22.04 LTS」のイメージにも反映される予定です。

変更はopenssh-server 1:9.0p1-1ubuntu1から

本仕様変更は「openssh-server 1:9.0p1-1ubuntu1」から行われています。
すでに「Ubuntu 22.10」では、現時点でさらにバージョンが進んだ「openssh-server 1:9.0p1-1ubuntu3」を利用できるようになっています。

openssh-serverの変更点

「openssh-server 1:9.0p1-1ubuntu1」以降の変更点は、以下のようになっています。

openssh (1:9.0p1-1ubuntu3) kinetic; urgency=medium

  * Document in the default sshd_config file the changes in behavior
    triggered by use of socket-based activation.

 -- Steve Langasek <steve.langasek@ubuntu.com>  Fri, 26 Aug 2022 00:40:11 +0000

openssh (1:9.0p1-1ubuntu2) kinetic; urgency=medium

  * Fix manpage to not claim socket-based activation is the default on
    Debian!

 -- Steve Langasek <steve.langasek@ubuntu.com>  Fri, 26 Aug 2022 00:21:42 +0000

openssh (1:9.0p1-1ubuntu1) kinetic; urgency=medium

  * debian/patches/systemd-socket-activation.patch: support systemd
    socket activation.
  * debian/systemd/ssh.socket, debian/systemd/ssh.service: use socket
    activation by default.
  * debian/rules: rejigger dh_installsystemd invocations so ssh.service and
    ssh.socket don't fight.
  * debian/openssh-server.postinst: handle migration of sshd_config options
    to systemd socket options on upgrade.
  * debian/README.Debian: document systemd socket activation.
  * debian/patches/socket-activation-documentation.patch: Document in
    sshd_config(5) that ListenAddress and Port no longer work.
  * debian/openssh-server.templates, debian/openssh-server.postinst: include
    debconf warning about possible service failure with multiple
    ListenAddress settings.

 -- Steve Langasek <steve.langasek@ubuntu.com>  Fri, 19 Aug 2022 20:43:16 +0000

Ubuntu 22.10をクリーンインストールする場合

「Ubuntu 22.10」をクリーンインストールする場合、ユーザーから見て完全に透過的になるように対応されるため、気にしなくても良いでしょう。
ただ以下の影響にも目を通しておくと、何かの役に立つかもしれません。

Ubuntu 22.04 LTSからアップグレードする場合

「Ubuntu 22.04 LTS」から「Ubuntu 22.10」へアップグレードする場合、以下の影響があります。

設定場所の変更

まず「/etc/ssh/sshd_config」で「ListenAddress」や「Port」を設定している場合、これらに相当する設定は「/etc/systemd/system/ssh.socket.d/addresses.conf」で行います。
この変更に伴い「/etc/ssh/sshd_config」ファイルでは、該当する設定に以下の説明が記述されています。

# Port and ListenAddress options are not used when sshd is socket-activated,
# which is now the default in Ubuntu.  See sshd_config(5) and
# /usr/share/doc/openssh-server/README.Debian.gz for details.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

また「sshd_config」にも該当する設定に以下の説明が記述されています。

  • sshd_config — OpenSSH daemon configuration file

ListenAddress
    Specifies the local addresses sshd(8) should listen on.  The following forms may be
    used:

        ListenAddress hostname|address
        ListenAddress hostname:port
        ListenAddress IPv4_address:port
        ListenAddress [hostname|address]:port

    If port is not specified, sshd will listen on the address and all Port options
    specified.  The default is to listen on all local addresses.  Multiple ListenAddress
    options are permitted.

    Note: On Ubuntu, the openssh-server package is configured to use systemd socket-
    based activation by default.  Therefore if you are using systemd with the default
    configuration, ListenAddress options will not be honored.  Address configuration
    must be handled in /etc/systemd/system/ssh.socket.d instead.

ListenAddressとListenStream設定は意味が異なる

次に従来の「ListenAddress」設定と移行後の「ListenStream」設定では、設定の意味が異なっており、起動時にここで設定されたアドレスが存在しない場合、既定では「ssh.socket」ユニットが起動しなくなります。

  • systemd.socket - Socket unit configuration

ListenStream=, ListenDatagram=, ListenSequentialPacket=
    Specifies an address to listen on for a stream (SOCK_STREAM), datagram (SOCK_DGRAM),
    or sequential packet (SOCK_SEQPACKET) socket, respectively. The address can be written
    in various formats:

    If the address starts with a slash ("/"), it is read as file system socket in the
    AF_UNIX socket family.

    If the address starts with an at symbol ("@"), it is read as abstract namespace socket
    in the AF_UNIX family. The "@" is replaced with a NUL character before binding. For
    details, see unix(7).

    If the address string is a single number, it is read as port number to listen on via
    IPv6. Depending on the value of BindIPv6Only= (see below) this might result in the
    service being available via both IPv6 and IPv4 (default) or just via IPv6.

    If the address string is a string in the format "v.w.x.y:z", it is interpreted as IPv4
    address v.w.x.y and port z.

    If the address string is a string in the format "[x]:y", it is interpreted as IPv6
    address x and port y. An optional interface scope (interface name or number) may be
    specified after a "%" symbol: "[x]:y%dev". Interface scopes are only useful with
    link-local addresses, because the kernel ignores them in other cases. Note that if an
    address is specified as IPv6, it might still make the service available via IPv4 too,
    depending on the BindIPv6Only= setting (see below).

    If the address string is a string in the format "vsock:x:y", it is read as CID x on a
    port y address in the AF_VSOCK family. The CID is a unique 32-bit integer identifier
    in AF_VSOCK analogous to an IP address. Specifying the CID is optional, and may be set
    to the empty string.

    Note that SOCK_SEQPACKET (i.e.  ListenSequentialPacket=) is only available for AF_UNIX
    sockets.  SOCK_STREAM (i.e.  ListenStream=) when used for IP sockets refers to TCP
    sockets, SOCK_DGRAM (i.e.  ListenDatagram=) to UDP.

    These options may be specified more than once, in which case incoming traffic on any
    of the sockets will trigger service activation, and all listed sockets will be passed
    to the service, regardless of whether there is incoming traffic on them or not. If the
    empty string is assigned to any of these options, the list of addresses to listen on
    is reset, all prior uses of any of these options will have no effect.

    It is also possible to have more than one socket unit for the same service when using
    Service=, and the service will receive all the sockets configured in all the socket
    units. Sockets configured in one unit are passed in the order of configuration, but no
    ordering between socket units is specified.

    If an IP address is used here, it is often desirable to listen on it before the
    interface it is configured on is up and running, and even regardless of whether it
    will be up and running at any point. To deal with this, it is recommended to set the
    FreeBind= option described below.

「Ubuntu」のアップグレード後にマシンを再起動しますが、その時にユーザーが「OpenSSH」で行っている設定でアップグレード後も問題なく「ssh.socket」ユニットを起動できるかどうかをアップグレードツール側で判別できないため、ユーザーはアップグレード後にsshで接続できるかどうか確認しておく必要があります。

振る舞いを元に戻すことも可能

振る舞いを元に戻すこと(変更前に戻すこと)も可能です。
変更を元に戻す方法は、以下のファイルに記述されています。

  • /usr/share/doc/openssh-server/README.Debian.gz

Socket-based activation with systemd
------------------------------------

By default, socket-based activation is used on systems that use systemd.

The provided ssh.socket unit file sets ListenStream=22.  If you need to have
it listen on a different address or port, then you will need to do this as
follows (modifying ListenStream to match your requirements):

  mkdir -p /etc/systemd/system/ssh.socket.d
  cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF
  [Socket]
  ListenStream=2222
  EOF
  systemctl daemon-reload

See systemd.socket(5) for details.

If you do not want to use socket activation for ssh on your system, you
can disable socket activation by running:

  systemctl disable --now ssh.socket
  systemctl enable --now ssh.service

Ubuntu
スポンサー
コメント
コメントポリシー
コメントをする前に UbuntuのCode of Conduct(CoC/行動規範) を確認し、CoCに沿ったコメントをお願いします。
コメントの使い方は、コメントの使い方を参照してください。
同一カテゴリーの記事
SNS
人気の記事
  • Ubuntu 26.04 その74 - Chromium 系ブラウザーにより、Qt6 で構築されたアプリがクラッシュする現象
    Qt6 で構築されたアプリがクラッシュする現象 Chromium 系ブラウザーにより、Qt6 で構築されたアプリがクラッシュする現象が報告されています。
  • Ubuntu 24.04 その104 - Ubuntu 26.04 LTS へアップグレードするには・アップグレードの注意事項
    Ubuntu 26.04 LTS へアップグレードするには 現在 Ubuntu 24.04 LTS を利用しているユーザーは、Ubuntu 26.04 LTS へアップグレードできます。
  • Ubuntu 26.10 その35 - RISC-V 向け Ubuntu Desktop 登場
    RISC-V 向け Ubuntu Desktop 登場 Ubuntu Desktop 26.10 では、RISC-V 向けデスクトップイメージがリリースされます。
  • Ubuntu 24.04 その103 - Ubuntu 26.04 LTS へアップグレード可能に・2年分の変化が一気にやってくる
    Ubuntu 26.04 LTS へアップグレード可能に 2026年9月29日、Ubuntu 24.04 LTS から Ubuntu 26.04 LTS へアップグレード可能になりました。
  • Ubuntu 26.10 その34 - Ubuntu と Rust に対する取り組み(2026年10月)
    Ubuntu と Rust に対する取り組み 2026年10月1日、Ubuntu と Rust に対する取り組みが以下で紹介されました。
  • Ubuntu 26.10 その33 - Ubuntu 26.10 β版がリリースされました・ディスクイメージのダウンロード
    Ubuntu 26.10 β版がリリースされました 2026年10月1日、Ubuntu 26.10 β版 がリリースされました。
  • Ubuntu 26.10 その38 - Ubuntu 26.10 がリリースされました・ディスクイメージのダウンロード
    Ubuntu 26.10 リリース 2026年10月15日、Ubuntu 26.10 がリリースされました。
  • Ubuntu 26.04 その76 - CVE-2026-92392 含む curl の脆弱性22件修正・アップデートを
    curl の脆弱性22件修正 CVE-2026-92392 含む22件の curl の脆弱性に対応したセキュリティーアップデートがリリースされました。
  • Linux その440 - uutils coreutils 0.11.0 でコマンド実行時のエラーメッセージを大幅に改良
    コマンド実行時のエラーメッセージを大幅に改良 uutils coreutils 0.11.0 で、コマンド実行時のエラーメッセージが大幅に改良されました。
  • Ubuntu 26.10 その32 - Snapdragon X2 に対応した Ubuntu 26.10 実験版登場
    Snapdragon X2 に対応した Ubuntu 26.10 実験版登場 2026年9月29日、Snapdragon X2 に対応した Ubuntu 26.10 実験版が登場しました。
記事のピックアップ
オプション