Files
nexus/wiki/concepts/SSH-Socket-Activation.md

37 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "SSH Socket Activation"
type: concept
tags: [ssh, ubuntu, systemd, server]
---
## Definition
Socket Activation 是 Ubuntu 24.04 引入的 SSH 服务管理机制ssh.socket 监听 22 端口,仅当有连接请求进入时才启动 sshd.service替代旧版本的常驻 ssh.service。
## Traditional Mode vs Socket Activation
| 特性 | 传统模式ssh.service | Socket Activationssh.socket|
|------|------------------------|-------------------------------|
| 进程状态 | sshd 常驻运行 | 按需启动,空闲时无进程 |
| 资源占用 | 持续占用内存 | 空闲时零资源占用 |
| 启动速度 | 已启动 | 有连接时首次略慢 |
| 管理命令 | systemctl restart sshd | systemctl restart ssh |
## Ubuntu 24.04 管理命令
```bash
# 启动并开机自启
sudo systemctl start ssh
sudo systemctl enable ssh
# 检查 socket 监听状态
sudo systemctl status ssh.socket
# 切回传统常驻模式
sudo systemctl disable --now ssh.socket
sudo systemctl enable --now ssh.service
```
## Core Insight
Socket Activation 符合最小权限原则没有连接需求时SSH 守护进程根本不存在,减少攻击面。
## Source
- [[Ubuntu 24.04 启用 SSH 服务]]