众所周知,Linux默认远程登录的端口为22.因此22端口暴露在大庭广众之下,像个没穿衣服的小姑娘,被坏人觊觎。
不巧本人一台VPS的22端口前些日子被人暴力破解,便把我的VPS端口做了更改。
此方法不适用于Centos7
首先以root用户登录你的linux系统
输入:
vi /etc/ssh/sshd_conig
你会看到
# $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
#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
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
"sshd_config" 139L, 3907C
按下i进入vi的输入命令,将光标下移到#Port 22并把#删去。
再其后输入Port 1024
(注:输入你想要的数字即可,但要避开一些常用端口。)
此处原本的#Port 22是作为注释所用的。此时我们删去#并保留Port 22是为了防止端口修改错误导致无法登陆。
修改好后按Esc键退出输入命令。
效果如下:
Port 22
Port 1024
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
然后
:wq
保存并退出vi
最后,重启sshd服务器
systemctl restart sshd
现在重新登陆即可。
登陆成功后再次按上述方法把SSH的默认端口Port 22 删去即可。
<h4>最后,因为Centos7本身的防火墙问题,我并无法做到修改端口。会在近期学会并写出来。</h4> 本文转自:鸡蛋君的博客
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有