CentOS7下安装配置SSH服务
安装前准备
1. 以root用户或sudo权限登录系统
2. 执行命令检查现有SSH状态:systemctl status sshd
安装OpenSSH服务
执行安装命令:yum install openssh-server -y
等待安装完成后验证版本:sshd -v
启动SSH服务
立即启动服务:systemctl start sshd
设置开机自启:systemctl enable sshd
防火墙配置
允许默认22端口:firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
客户端连接验证
使用终端工具连接测试:ssh username@服务器IP
返回登录提示表明服务运行正常
基础安全配置(可选)
编辑配置文件:vi /etc/ssh/sshd_config
• 修改默认端口:Port 2222
• 禁用root登录:PermitRootLogin no
重载配置:systemctl restart sshd
常见问题处理
• 连接失败时检查:systemctl status sshd
• 查看日志定位问题:journalctl -u sshd