在安装openssh-server的情况下执行以下操作:
vi /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# 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
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
去掉Port前面的注释更改后面端口即可
然后重启ssh服务:
systemctl restart sshd
在防火墙中放行更改的端口
firewall-cmd --zone=public --add-port=更改的端口号/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --query-port=更改的端口号/tcp
评论区