一、背景介绍
SSH 为 Secure Shell
由 IETF 的网络工作小组(Network Working Group)所制定;
SSH 是建立在应用层和传输层基础上的一种安全协议。
SSH传输数据是加密的,可以有效防止传输过程被截取数据保障安全。
SSH的数据是经过压缩的,所以可以加快传输的速度
sshd服务安装后,默认以22
端口对外提供服务,很多时候,这个端口并不安全,一般安装时即额外指定为其他端口。
二、步骤
1、查看本机系统属性
[root@server111-111 root]# lsb_release -a
如果无该命令,安装之:yum -y install redhat-lsb
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
2、查看是否已安装ssh服务
[root@server111-111 root]# rpm -qa|grep ssh
openssh-7.4p1-16.el7.x86_64
libssh2-1.4.3-12.el7.x86_64
openssh-clients-7.4p1-16.el7.x86_64
openssh-server-7.4p1-16.el7.x86_64
3、修改默认端口
vim /etc/ssh/sshd_config
####### If you want to change the port on a SELinux system, you have to tell
######## SELinux about this change.
######## semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
Port 11122
4、重启sshd服务
systemctl restart sshd
5、关于防火墙
如果设置有防火墙,需要修改增加防火墙规则,或关闭防火墙,如下:
iptables -F
或
停止防火墙,并禁用这个服务
systemctl stop firewalld.service
systemctl disable firewalld.service
备注:
从centos7之后,防火墙服务名更改为firewalld,但底层仍是由iptables实现。
6、验证登录流程
在其他主机上,测试:
ssh -p 11122 111.111.111.111
如果不报如下端口错误:
ssh: connect to host 111.111.111.111 port 11122: Connection refused
即配置成功。