vim /etc/ssh/sshd_config
没安装vim则用
vi /etc/ssh/sshd_config
在#Port 22行去掉#号注释,同时加入想要使用的端口号如 Port 61228
# 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 22
Port 61228
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
保留22端口是为了防止当前无法使用ssh登录
ecs退出编辑
:wq
回车保存
重启ssh
systemctl restart sshd.service
ssh使用新端口登录,登录成功则下一步
关闭22端口
vi /etc/ssh/sshd_config
将之前开放的Port 22一行注释掉并保存
# 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 61228
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
重启ssh
systemctl restart sshd.service
---end---