
新服务器配置
...大约 2 分钟
在新服务器/重装系统后推荐进行的配置
更新系统
apt update && apt upgrade -y
创建非root用户并添加到sudo组
$ apt install -y sudo
$ adduser <username>
$ usermod -aG sudo <username>
$ su <username>
设置ssh登录
$ mkdir -p ~/.ssh
$ nano ~/.ssh/authorized_keys
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
加固ssh安全
$ sudo vim /etc/ssh/sshd_config
PubkeyAuthentication yes # 启用密钥登录
PasswordAuthentication no # 禁用密码登录
PermitRootLogin no # 禁止root直接登录
$ sudo systemctl restart sshd
本地配置 ~/.ssh/config
Host <hostname>
HostName server_ip
User username
IdentityFile ~/.ssh/id_ed25519
注意
完成后不要关闭当前连接,在新的终端窗口进行测试是否能够正确登录,以操作失误导致无法登录服务器。
配置 fail2ban
$ sudo apt install -y fail2ban
$ sudo tee /etc/fail2ban/jail.local > /dev/null <<'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 3
ignoreip = 127.0.0.1/8 ::1
[sshd]
enabled = true
# 使用systemd后端(推荐,适用于Debian 10+)
backend = systemd
mode = aggressive
EOF
$ sudo systemctl enable fail2ban # 启动服务
$ sudo systemctl status fail2ban # 检查状态
配置时区和NTP
$ sudo timedatectl set-timezone Asia/Shanghai
$ apt install -y systemd-timesyncd
$ timedatectl set-ntp true
测试 VPS 性能(可选)
一键测试脚本(NodeQuality)
$ bash <(curl -sL https://run.NodeQuality.com)
安装Docker(可选)
一键脚本:
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
加入Docker组:
$ sudo usermod -aG docker $USER
$ newgrp docker # 刷新组,也可重新登录
Powered by Waline v3.8.0
