22端口容易被網絡暴力,換個不常用的端口
一、修改端口號
# 修改sshd_config
vim /etc/ssh/sshd_config
# 修改 Port 爲自定端口號
Port 10127
# 開啓端口讓10217能訪問
firewall-cmd --zone=public --add-port=10127/tcp --permanent
# 重啓防火牆
systemctl restart firewalld.service
二、向SELinux中添加修改的SSH端口
# 向SELinux中添加修改的SSH端口
yum provides semanage
yum -y install policycoreutils-python
semanage port -l | grep ssh
# 添加端口10127
semanage port -a -t ssh_port_t -p tcp 10127
# 移除端口22345(22端口爲默認端口,不能移除)
semanage port -d -t ssh_port_t -p tcp 22345
# 重啓ssh
systemctl restart sshd.service
三、禁止使用密碼登錄
# 確認修改後的端口 10127 可以正常連接後刪除/etc/ssh/sshd_config文件的22端口
vim /etc/ssh/sshd_config
# 注意注意!!!下面的步驟爲密鑰登錄,需要先設置密鑰登錄!!!
# 現在我們禁止密碼登錄,只允許使用密鑰登錄,修改PasswordAuthentication爲no
PasswordAuthentication no
# 重啓sshd
systemctl restart sshd.service
現在就只能使用密鑰登錄了,輸入正確的密碼也登錄不了,這樣媽媽再也不用擔心別人暴力破解了。