Linux的SSH默认22端口更改
文章目录
一、修改sshd配置文件
二、重启ssh服务
三、总结
默认22的SSH连接端口很容易受攻击,故通过修改默认端口来达到一定的防护作用。
一、修改sshd配置文件
查看目前ssh连接端口
sudo netstat -tunlp | grep "ssh"
1
目前默认指向的就是22端口,接下来我们通过修改/etc/ssh/sshd_config的配置文件来达到修改连接端口的目的:
sudo vim /etc/ssh/sshd_config
1
这里需要重点关注#Port 22的位置,由于默认就是22端口所以该行是被注释的,我们测试接下来用2020端口来连接SSH,因为可以存在多个SSH连接端口,这里我们先暂时保留22端口,修改如下:
# $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
Port 2020
#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
# Ciphers and keying
#RekeyLimit default none
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
二、重启ssh服务
重启ssh命令需要根据服务器系统的版本,CentOS 6及以下
sudo service ssh restart
1
CentOS 7及以上
systemctl restart sshd
1
再次查看当前开放的SSH连接端口
sudo netstat -tunlp | grep "ssh"
1
由于22端口和2020端口同时开放,所以理论结果应该会显示这两个端口,测试一下2020端口是否能够连接成功,若测试成功后即按照上述步骤在配置文件里将22端口去除后重启ssh服务即达到了我们更改22默认连接端口的目的。
三、总结
通过调整默认连接端口达到一定的防护作用,需在了解系统版本的基础上进行调整。
————————————————
版权声明:本文为CSDN博主「imVainiycos」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/imVainiycos/article/details/109841406
浙公网安备 33010602011771号