第二十八期-改SSH登录端口

发布于 2020-07-04  265 次阅读


写了上一期的教程,还是觉得不要直接把22端口暴露在外面,就来写一篇改端口教程,这一篇有点水,谅解一下。。。

vim /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 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
...

#Port 22

这里Port 22被注释了,光标通过键盘上的箭头移到#,按x删掉前面的#
然后按I,把22改成你想要的端口
然后

:wq

保存并退出编辑器

随后

systemctl restart sshd.service

然后在服务器内的防火墙添加放行

firewall-cmd --zone=public --add-port=你的ssh端口号/tcp --permanent

云服务器记得放行安全组

完事

李天成 2020/07/04 15:30
转载请注明出处。


Skyler & Harry 's Notes