ubuntu和centos更改ssh端口,小白实测可用,成功修改端口,登陆成功

时间:4年前   阅读:7259

一、修改ssh配置文件sshd_config:

vi /etc/ssh/sshd_config

看到下面的信息,找到 Port 22那行,把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 #这一行的端口改为你要的
#ListenAddress 0.0.0.0
#ListenAddress ::

二、防火墙放行:

vi /etc/sysconfig/iptables

找到这个文件里面下面的这两行:

-A IN_public_allow -p udp -m udp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
-A IN_public_allow -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT

复制这两行把22改为你要修改的端口就好

或者直接把22修改了也行,这样就不用22端口了

然后保存退出

三、重启防火墙和ssh:

service sshd restart #重启ssh 二选一
systemctl restart sshd.service  #重启ssh 二选一
service iptables restart  #重启防火墙


大功告成,可以用新端口登陆了,22端口就不能登陆了,防止ssh暴力攻击

微信扫码关注

更新实时通知

上一篇:50etf期权中进行组合策略套利的风险是什么?

下一篇:Ubuntu忘记登陆密码后,如何破解修改登录密码,重新进入系统

网友评论

请先 登录 再评论,若不是会员请先 注册