Ubuntu server的防火墙配置问题,包括新用户添加、防火墙规则设定以及ssh的简单设置,写得比较简单,慢慢理解以后来填坑。主要的references见文末,另外说一句 Merry Xmas!
Change or update root pwd
修改或者初始化root的密码,如下
| 1 2 3
 | sudo passwd root New password: xxxx Retype new password: xxxx
 | 
Add a new user
Ubuntu server在安装好以后只有Root用户,为了方便管理,通常需要添加一个用户以方便管理,并且为了服务器的安全性,需要配置ssh的key only和防火墙。
| 1 2 3 4 5 6 7 8 9 10 11
 | sudo apt update  sudo apt upgrade  sudo apt install vim  sudo adduser jason   sudo usermod -G root jason  sudo chmod u+w /etc/sudoers  sudo vim /etc/sudoers jason ALL=(ALL:ALL) ALL sudo chmod u-w /etc/sudoers 
 | 
SSH confiurations
ssh配置方便远程访问server,主要的配置包括端口修改、aurhorized_keys以及一些有助于安全性的配置。
1. 生成本机的Authentication key-pair
选择默认的id_rsa和id_rsa.pub存储密钥对,并且选择不设定密码。
2. 添加该用户的public key到server中
| 1 2 3 4 5 6
 | mkdir ~/.ssh cd ~/.ssh touch authorized_keys vim authorized_keys ssh-rsa xxxxx user@xxx
 | 
3. 配置ssh端口及相应的安全选项
sshd的配置文件存放在/etc/ssh/sshd_config中,
| 1 2 3 4 5 6 7
 | vim /etc/ssh/sshd_config Port 2333  PermitRootLogin no PasswordAuthentication no
 | 
4. 重启ssh服务
配置完成后,重启sshd服务,如下
| 1
 | sudo systemctl restart sshd
 | 
UFW configuration
详细的UFW配置参考这篇文章,下面列出我的配置并对解释。
| 1 2 3 4 5 6 7 8 9 10 11 12
 | sudo apt install ufw sudo ufw default allow outgoing sudo ufw default deny incoming sudo ufw allow ssh sudo ufw allow 80/tcp sudo ufw allow http/tcp sudo ufw allow 1725/udp sudo ufw enable
 | 
用sudo ufw status查看ufw的运行状态和配置结果,若显示如下列表,则说明配置好了,
| 1 2 3 4 5 6 7 8 9 10
 | Status: active To                         Action      From --                         ------      ---- 80/tcp                     ALLOW       Anywhere                   1725/udp                   ALLOW       Anywhere                   2333                       ALLOW       Anywhere                   80/tcp (v6)                ALLOW       Anywhere (v6)              1725/udp (v6)              ALLOW       Anywhere (v6)              2333 (v6)                  ALLOW       Anywhere (v6)
 | 
References