OpenSSH 是一套用于安全远程登录和文件传输的开源工具,广泛应用于各类操作系统。本文将详细介绍在不同系统中安装 OpenSSH 的方法。
大多数 Linux 发行版默认已安装 OpenSSH 客户端,但若需使用 SSH 服务(即作为服务器),请运行以下命令:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
# 安装 OpenSSH 服务
sudo yum install openssh-server # CentOS 7 及更早版本
# 或
sudo dnf install openssh-server # CentOS 8+ / Fedora
# 启动并设置开机自启
sudo systemctl start sshd
sudo systemctl enable sshd
Windows 10 1809 版本及以上已内置 OpenSSH 客户端和服务器(可选功能):
或通过 PowerShell(以管理员身份运行)安装:
# 安装客户端
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# 安装服务器
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# 启动服务
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
macOS 自带 OpenSSH 客户端,终端中可直接使用 ssh 命令。如需开启 SSH 服务(远程登录):
在终端中输入以下命令,若显示版本信息则表示客户端已安装:
ssh -V
检查 SSH 服务是否运行(Linux/macOS):
sudo systemctl status ssh # Ubuntu/Debian sudo systemctl status sshd # CentOS/Fedora