2025-0211更新:新版本添加了include配置,需要删除掉,否则无法正常使用密码登录
所有命令整合
Ubuntu:
sudo sed -i 's/^Include\ \/etc\/ssh\/sshd_config.d\/.*//' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?UseDNS.*/UseDNS\ no/g' /etc/ssh/sshd_config && sudo service sshd restart && sudo iptables -P INPUT ACCEPT && sudo iptables -P FORWARD ACCEPT && sudo iptables -P OUTPUT ACCEPT && sudo iptables -F && sudo apt-get purge netfilter-persistent -y
Centos:
sudo sed -i 's/^Include\ \/etc\/ssh\/sshd_config.d\/.*//' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?UseDNS.*/UseDNS\ no/g' /etc/ssh/sshd_config && sudo service sshd restart && sudo systemctl stop firewalld && sudo systemctl disable firewalld
关闭防火墙端口
一键命令:
Ubuntu:开放端口并卸载防火墙
sudo iptables -P INPUT ACCEPT && sudo iptables -P FORWARD ACCEPT && sudo iptables -P OUTPUT ACCEPT && sudo iptables -F && sudo apt-get purge netfilter-persistent -y
Centos:关闭防火墙并关闭关机自启
sudo systemctl stop firewalld && sudo systemctl disable firewalld
详细命令解析:
# 开放所有端口
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F
# 删除防火墙
sudo apt-get purge netfilter-persistent && reboot
或 sudo rm -rf /etc/iptables && reboot
开启ssh的密码登录以及关闭DNS解析
一键命令:
关闭DNS解析:
sudo sed -i 's/^Include\ \/etc\/ssh\/sshd_config.d\/.*//' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?UseDNS.*/UseDNS\ no/g' /etc/ssh/sshd_config && sudo service sshd restart
不关闭DNS解析:
sudo sed -i 's/^Include\ \/etc\/ssh\/sshd_config.d\/.*//' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin\ yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config && sudo service sshd restart
命令解析
sudo sed -i 's/^Include\ \/etc\/ssh\/sshd_config.d\/.*//' /etc/ssh/sshd_config
# 将新增的Include行删除
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin\ yes/g' /etc/ssh/sshd_config
# 将注释的 PermitRootLogin 改为启用
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config
# 将注释的 PasswordAuthentication 改为启用
sudo sed -i 's/^#\?UseDNS.*/UseDNS\ no/g' /etc/ssh/sshd_config
# 将注释的 UseDNS 改为禁用
sudo service sshd restart
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容