SSH服务安装与配置
在Linux系统中配置SSH服务需执行以下步骤:
- 安装SSH服务:使用
yum install openssh-server
或apt install openssh-server
命令安装 - 启动服务:执行
systemctl start sshd
并设置开机自启systemctl enable sshd
- 修改配置文件:编辑
/etc/ssh/sshd_config
,建议启用以下参数:PermitRootLogin yes
(允许root登录)PasswordAuthentication yes
(启用密码验证)
- 生成SSH密钥:使用
ssh-keygen
创建密钥对,并通过ssh-copy-id user@server
部署公钥
远程桌面连接方法
Windows系统可通过以下步骤启用SSH远程连接:
- 安装OpenSSH组件:执行PowerShell命令
Add-WindowsCapability -Online -Name OpenSSH.Server
- 启动SSH服务:运行
Start-Service sshd
并设置自动启动Set-Service -Name sshd -StartupType 'Automatic'
- 连接测试:在客户端使用
ssh username@hostname
命令进行连接
端口设置与防火墙配置
优化服务器安全需注意以下配置:
- 修改默认端口:在
sshd_config
中设置Port 2222
等非标准端口 - 防火墙放行:Linux系统使用
ufw allow 2222
,Windows需配置防火墙入站规则 - 端口测试:通过
netstat -lntup | grep ssh
验证服务监听状态