目录
一、安装SSH
1、使用yum或者rpm命令确认SSH服务是否已安装;
yum list installed | grep openssh 或者 rpm -qa | grep openssh
2、如果没有安装,使用yum命令安装一下;
yum install openssh-server.x86_64
二、启动SSH
1、配置SSHD配置文件(需要root权限)
vim /etc/ssh/sshd_config
配置SSH端口(默认22),允许root及密码连接
像这种情况,如果保持默认,也可以不进行修改
以root用户连接
使用密码方式认证
保存后退出
2、启动SSH或重启SSH服务
systemctl start sshd(或/bin/systemctl start sshd.service)
systemctl restart sshd(或/bin/systemctl restart sshd.service)
3、查看当前运行状态
systemctl status sshd
4、检查服务监听状态
netstat -anpt | grep 22
三、配置防火墙
1、检查防火墙开启状态
centos的默认防火墙是firewall
systemctl status firewalld
如果防火墙未开启,可以参考开启ssh命令开启下
2、防火墙添加放行22端口
firewall-cmd --add-port=22/tcp --permanent
PS:加入--permanent参数是为了这个操作永久生效
3、重新加载防火墙规则
firewall-cmd --reload
4、SSH服务和防火墙都加到开机自启
systemctl enable sshd.service
systemctl enable firewalld.service
查看添加的结果
systemctl list-units --type=service | grep ssh
systemctl list-units --type=service | grep firewall
四、测试SSH连接是否正常
五、解决问题
暂时未遇到问题,后续遇到问题再同步更新~·
感谢阅读