systemctl 、
时间: 2025-01-18 08:53:33 浏览: 28
### systemctl 使用方法及常见命令
#### 管理服务状态
可以利用 `systemctl` 来查询、启动、停止以及重启特定的服务。
对于想要检查某个服务的状态,比如 SSH 服务,可执行如下指令:
```bash
systemctl status sshd.service
```
要激活一个未运行的服务,则应采用 start 参数[^1]:
```bash
sudo systemctl start sshd.service
```
当需要关闭正在运作中的服务时,stop 动作会被调用:
```bash
sudo systemctl stop sshd.service
```
如果希望重新加载配置文件并使更改生效而不中断现有连接,restart 是合适的选择:
```bash
sudo systemctl restart sshd.service
```
为了确保系统下次引导时自动开启某项服务,enable 指令会很有帮助;而 disable 则相反,它阻止该服务随系统一同启动:
```bash
sudo systemctl enable sshd.service
sudo systemctl disable sshd.service
```
#### 查询已启用单位文件
通过组合使用 list-units 和 grep 工具来筛选出已被设置成开机自启的服务列表[^4]:
```bash
systemctl list-unit-files | grep enabled
```
#### 查看当前活动单元
list-units 可展示所有处于活跃状态下的单元概览,这对于快速掌握系统的整体状况非常有用[^2]:
```bash
systemctl list-units --type=service --state=active
```
阅读全文
相关推荐


















