本文以Debian 10为例,介绍如何对服务器进行初步配置,本文同样完全适用于 Ubuntu20.04系统。
基础设置
更改密码:
1 | passwd |
更新系统:
1 | apt update && apt full-upgrade -y && apt autoremove -y |
安装常用软件:
1 | apt install sudo wget curl htop vim git ffmpeg aria2 zsh zip unzip man npm nodejs speedtest-cli python3 python3-pip ufw fail2ban certbot nginx -y |
安装python3常用库:
1 | pip3 install requests bs4 lxml python-telegram-bot you-get youtube-dl gdown m3u8downloader fake_useragent faker pyexecjs |
添加新用户:
1 | adduser chan |
将新用户添加至sudo组:
1 | usermod -aG sudo chan |
安全设置
ssh设置
修改ssh配置文件
1 | vim /etc/ssh/sshd_config |
修改ssh端口:
1 | Port 2333 |
禁止root远程登录:
1 | PermitRootLogin no |
安装fail2ban防ssh爆破:
1 | cd /etc/fail2ban |
sshd处加上 enabled = true,并将所有默认ssh端口为2333
防火墙设置
开启防火墙,仅放行ssh端口
1 | ufw allow 2333 |
性能优化
TCP传输优化
查看是否已开启BBR:
1 | sysctl net.ipv4.tcp_available_congestion_control |
如果没有则开启BBR:
1 | echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf |
调整swap大小
1 | wget https://www.moerats.com/usr/shell/swap.sh && bash swap.sh |
个性化配置
配置shell
安装oh-my-zsh
1 | wget https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/tools/install.sh && bash install.sh |
添加自动补全插件:
1 | git clone https://github.com.cnpmjs.org/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions |
添加语法高亮插件:
1 | git clone https://github.com.cnpmjs.org/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting |
修改配置文件~/.zshrc
,修改主题及插件:
1 | ZSH_THEME="ys" |
配置vim
安装spf13-vim
1 | sh <(curl https://j.mp/spf13-vim3 -L) |
启用鼠标复制粘贴
编辑/etc/vim/vimrc.local
,添加如下内容
1 | source /usr/share/vim/vim81/defaults.vim |
F5执行脚本
将下面的配置放到.vimrc文件即可:
1 | """""""""""""""""""""" |
参考
https://blog.chaos.run/dreams/ubuntu-server-starting-settings
https://github.com/fail2ban/fail2ban/wiki/Proper-fail2ban-configuration