OpenSSH 是一套用于安全远程登录和其他网络服务的开源工具。本文将指导您在常见 Linux 发行版上安装和启用 OpenSSH 服务。
1. 在 Ubuntu / Debian 系统中安装 OpenSSH
大多数现代 Ubuntu 或 Debian 系统默认已安装 OpenSSH 客户端,但服务器组件可能需要手动安装。
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
2. 在 CentOS / RHEL / Rocky Linux 中安装 OpenSSH
这些系统通常也预装了 OpenSSH,但若未安装,可使用以下命令:
sudo yum install openssh-server # CentOS 7 及更早版本
# 或
sudo dnf install openssh-server # CentOS 8+ / Rocky Linux / Fedora
sudo systemctl enable sshd
sudo systemctl start sshd
3. 验证 SSH 服务是否运行
sudo systemctl status ssh # Ubuntu/Debian
sudo systemctl status sshd # CentOS/RHEL
确保输出中显示 active (running)。
4. 防火墙设置(如启用)
确保防火墙允许 SSH 流量(默认端口 22):
# Ubuntu/Debian (UFW)
sudo ufw allow ssh
# CentOS/RHEL (firewalld)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
5. 远程连接测试
从另一台机器使用 SSH 客户端连接:
ssh username@your_server_ip
至此,您已成功在 Linux 上安装并配置 OpenSSH 服务,可安全地进行远程管理。