一、系统更新
centos系统更新
PLAINTEXT
dnf upgrade --refresh -y && dnf install -y sudo curl二、VPS加固
1、创建普通用户并授权
PLAINTEXT
# 创建用户
useradd -m -s /bin/bash wahaha
# 设置密码
passwd wahaha
# 复制 root 的 ssh 密钥以允许新用户登录
cp -r /root/.ssh /home/wahaha/
chown -R wahaha:wahaha /home/wahaha/.ssh
# 允许 wahaha 用户免密执行 sudo
echo 'wahaha ALL=(ALL) NOPASSWD: ALL' | tee /etc/sudoers.d/wahaha-nopasswd
chmod 0440 /etc/sudoers.d/wahaha-nopasswd新开本地终端
PLAINTEXT
ssh wahaha@你的服务器IP
sudo whoami # 输出 root,无需输入密码
2、修改SSH端口号并配置UFW防火墙
PLAINTEXT
# 修改 SSH 端口(此处以 8866 为例)
sudo sed -i 's/^#Port 22/Port 8866/' /etc/ssh/sshd_config
sudo sed -i 's/^Port 22/Port 8866/' /etc/ssh/sshd_config
# 验证配置语法是否正确
sudo sshd -t
# 安装并重置 UFW 防火墙
sudo -i
sudo dnf install -y firewalld policycoreutils-python-utils
# 放行端口
if ! systemctl is-active --quiet firewalld; then
firewall-offline-cmd --add-service=ssh &&
systemctl enable --now firewalld
fi
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-port=8866/tcp
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
firewall-cmd --list-all
# ssh端口重加载生效
/usr/sbin/sshd -t && systemctl reload sshd
# 检查生效的 SSH 端口
/usr/sbin/sshd -T | grep '^port '
# 确认只显示 port 8866
firewall-cmd --permanent --remove-service=ssh
firewall-cmd --permanent --remove-port=22/tcp
firewall-cmd --reload
firewall-cmd --list-all
ss -lntp | grep sshd
3、禁用root登录
PLAINTEXT
# 修改 SSH 配置,禁止 root 登录
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
# 禁止密码登录
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
# 检查配置语法并重启 SSH 服务
sudo /usr/sbin/sshd -t && sudo systemctl reload sshd
sudo systemctl is-active sshd
# 检查全局配置是否符合预期
sudo /usr/sbin/sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication|port) '三、网络测试
PLAINTEXT
# 切换到 root 环境
sudo -i
# 运行融合怪脚本
bash <(curl -sL https://run.NodeQuality.com)
IP质量检测:
四、安装3x-ui面板
PLAINTEXT
# 安装/更新 3x-ui
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
Username: CfKU045Vly
Password: 6s7PolfvZO
Port: 55477
WebBasePath: gU7NzeDDNZHys8AuPA
Database: SQLite (/etc/x-ui/x-ui.db)
Access URL: https://185.184.223.251:55477/gU7NzeDDNZHys8AuPA
API Token: VthvHVXkfOcavbV53XaHuITjAiNUiA6l4kVwoNpaW4cME2hi
# 放行上面端口
firewall-cmd --permanent --add-port=55477/tcp
本文是原创文章,采用 CC BY-NC-SA 4.0 协议,完整转载请注明来自 avatar
评论
隐私政策
0/500
滚动到此处加载评论...

