淺談修改ssh端口

  • 查看ssh端口信息和防火牆信息
[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
  • ssh端口修改存放的配置文件
[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 ::
.........
  • 重啓sshd服務
[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
......
相關文章
相關標籤/搜索