适用于 Ubuntu、Debian、CentOS、RHEL 等主流发行版
OpenSSH(Open Secure Shell)是一套用于安全远程登录和其他网络服务的工具集,基于 SSH 协议。它能加密客户端与服务器之间的通信,防止窃听、连接劫持等攻击。
sudo apt update
sudo apt install openssh-server
sudo yum install openssh-server
# 或使用 dnf(较新版本)
sudo dnf install openssh-server
ssh -V
若返回版本信息(如 OpenSSH_8.9p1, OpenSSL 3.0.2 ...),说明客户端已安装;但服务端需单独安装 openssh-server。
安装完成后,通常需要手动启动并设置开机自启:
sudo systemctl start ssh # Ubuntu/Debian
sudo systemctl start sshd # CentOS/RHEL
sudo systemctl enable ssh # Ubuntu/Debian
sudo systemctl enable sshd # CentOS/RHEL
sudo systemctl status ssh # 或 sshd
sudo systemctl restart ssh
sudo systemctl reload ssh
/etc/ssh/sshd_config/var/log/auth.log/var/log/securesshd_config 后需重启或重载 SSH 服务才能生效。
确保系统防火墙允许 SSH 默认端口(22):
sudo ufw allow 22
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
从另一台机器测试 SSH 连接:
ssh username@your_server_ip
首次连接会提示确认主机指纹,输入 yes 继续。
/etc/ssh/sshd_config 中的 Port 行,并重启服务。/etc/ssh 目录及密钥文件权限正确(通常为 600 或 644)。