Centos 7: changing SSH-port

Deal with SSH (changing port) from 22

  1. cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.orig.$(date +%F)
    exisiting rule backup


     
  2.  nano /etc/ssh/sshd_config
    #
    Port 269
    #AddressFamily any


     
  3. The configuration file for the sshd daemon.
    systemctl restart sshd


     
  4.    firewall-cmd --permanent --zone=public --add-port=269/tcp
    Open the required ports
     
  5.    firewall-cmd --reload
    reload the firewall configuration
     
  6.    ss -tnlp|grep ssh

     
  7. firewall-cmd --list-all
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: eth0 eth1
      sources:
      services: dhcpv6-client ssh
      ports: 269/tcp
      protocols:
      masquerade: no
      forward-ports:
      source-ports:
      icmp-blocks:
      rich rules:
  8. systemctl restart sshd

    now we have to edit some more files, according the made changes

  9. nano /etc/services
    ssh             22/tcp                          # The Secure Shell (SSH) Protocol
    # ssh connection was modified to different location - port №269
    ssh             22/udp                          # The Secure Shell (SSH) Protocol

     
  10.  ls /usr/lib/firewalld/services
     cp /usr/lib/firewalld/services/ssh.xml /usr/lib/firewalld/services/ssh.xml.orig.$(date +%F)


     
  11. nano /usr/lib/firewalld/services/ssh.xml
      <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote m$
      <port protocol="tcp" port="269"/>
    </service>

    either sed -i 's|port="22"|port="269"|' /usr/lib/firewalld/services/ssh.xml
     
  12. systemctl restart sshd.service
  13. netstat -tunlp |grep ssh {yum install net-tools}
  14. REBOOT

 

Tags: