Press "Enter" to skip to content

Change Linux SSH Port from 22 to 2222

0

The default SSH port on all Operating Systems is port 22. For security measures, it is recommended to use other port instead, such as 2222, 2200.  The configuration file located in /etc/ssh/sshd_config folder


[opc@centos7-docker-portainer ~]$ sudo -i
[root@centos7-docker-portainer ~]#
[root@centos7-docker-portainer ~]# 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 2222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
[root@centos7-docker-portainer ~]# semanage port -a -t ssh_port_t -p tcp 2222

[root@centos7-docker-portainer ~]# sudo /sbin/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 2222 -j ACCEPT

[root@centos7-docker-portainer ~]# firewall-cmd –permanent –zone=public –add-port=2222/tcp
success
[root@centos7-docker-portainer ~]# firewall-cmd –reload
success
[root@centos7-docker-portainer ~]#/etc/init.d/sshd restart

Leave a Reply

%d bloggers like this: