[root@linux01 ~]# netstat -lntp|grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 846/sshd
tcp6 0 0 :::22 :::* LISTEN 846/sshd
[root@linux01 ~]# getenforce #关闭防火墙进入/etc/selinux/config配置文件设置Disabled即可
Disabled
[root@linux01 ~]# vi /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm 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 <----先把#取消掉,为防止端口修改失败作备用,修改成功后再注释即可
Port xxx <----添加这一条参数,表示你要修改的端口参数
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
.........
[root@linux01 ~]# service sshd restart
- 测试端口修改,xshell终端工具下修改session端口值,重新打开测试连通性
[root@linux01 ~]# netstat -lntp|grep ssh #执行该命令检测是否存在22和修改的端口值参数
- 以上步骤成功后,进入/etc/ssh/sshd_config配置文件注释22端口信息即可
- 修改/etc/services文件(标准端口配置文件,有些服务启动会去查找这文件登记的信息)
[root@linux01 ~]# cat /etc/services
......
ssh 22/tcp # The Secure Shell (SSH) Protocol #把这里的端口值替换成修改的值即可
ssh 22/udp # The Secure Shell (SSH) Protocol
......