前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >防止暴力破解,请更换SSH默认端口

防止暴力破解,请更换SSH默认端口

作者头像
用户1153097
发布2018-06-28 14:25:54
1.1K0
发布2018-06-28 14:25:54
举报
文章被收录于专栏:鸡蛋君

众所周知,Linux默认远程登录的端口为22.因此22端口暴露在大庭广众之下,像个没穿衣服的小姑娘,被坏人觊觎。

不巧本人一台VPS的22端口前些日子被人暴力破解,便把我的VPS端口做了更改。

此方法不适用于Centos7

首先以root用户登录你的linux系统

输入:

代码语言:javascript
复制
vi /etc/ssh/sshd_conig

你会看到

代码语言:javascript
复制
#       $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键退出输入命令。

效果如下:

代码语言:javascript
复制
Port 22
Port 1024
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

然后

代码语言:javascript
复制
:wq

保存并退出vi

最后,重启sshd服务器

代码语言:javascript
复制
systemctl restart sshd

现在重新登陆即可。

登陆成功后再次按上述方法把SSH的默认端口Port 22 删去即可。

<h4>最后,因为Centos7本身的防火墙问题,我并无法做到修改端口。会在近期学会并写出来。</h4> 本文转自:鸡蛋君的博客

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-03-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档