![](https://cdn.jsdelivr.net/gh/justincnn/pictures/img/202307231616878.png)
系统设置
更新软件库
1
| apt update -y && apt upgrade -y
|
更新、安装必备软件
1
| apt install sudo curl wget nano
|
校正系统时间
1
| sudo timedatectl set-timezone Asia/Shanghai
|
开启BBR加速
1
| wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
|
此时应该返回这样的结果:
添加SWAP
SWAP
对于内存小的VPS非常有必要,可以提高我们的运行效率。
1
| wget -O swap.sh https://raw.githubusercontent.com/yuju520/Script/main/swap.sh && chmod +x swap.sh && clear && ./swap.sh
|
开放所有的端口
先在oracle系统下设置开放端口
![rr87F3](https://cdn.jsdelivr.net/gh/justincnn/pictures@master/upic/rr87F3%20.png)
![](https://s2.loli.net/2024/12/21/IYLg2GjbkJmcF7h.png)
1.切换到root用户
2.开放所有端口
1
| sudo iptables -P INPUT ACCEPT
|
1
| sudo iptables -P FORWARD ACCEPT
|
1
| sudo iptables -P OUTPUT ACCEPT
|
3.Oracle自带的Ubuntu镜像默认设置了Iptable规则,关闭它
1
| apt-get purge netfilter-persistent
|
4.强制删除规则
1
| rm -rf /etc/iptables && reboot
|
删除oracle-cloud-agent,防止甲骨文监控
1
| snap remove oracle-cloud-agent
|
安装Fail2ban
fail2ban的配置文件通常位于 /etc/fail2ban/
目录下,fail2ban的.conf配置文件都是可以被.local覆盖,所以配置方式建议是添加.local文件,不修改原来的配置文件。
1
| vim /etc/fail2ban/jail.local
|
配置文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| [DEFAULT]
ignoreip = 127.0.0.1
allowipv6 = auto
backend = systemd
[sshd]
enabled = true
filter = sshd
port = ssh
action = iptables[name=SSH, port=ssh, protocol=tcp]
logpath = /var/log/secure
bantime = 86400
findtime = 86400
maxretry = 3
|
Ctrl+S保存并退出
1
| sudo systemctl enable fail2ban
|
1
| sudo systemctl restart fail2ban
|
1
| sudo systemctl status fail2ban
|
更改SSH端口
1、备份原sshd配置文件
1
| cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
|
2、修改sshd配置文件
可以使用winscp、nano、vim之类的软件编辑
查找Port 22,有可能 Port 22 是注释的(即前面有#号,有的话删掉 # 号)。
在 Port 22 下面添加一行 Port 3322 其中3322为你更改SSH后的端口。
这里建议先保留原来的22端口,待新的SSH端口测试正常工作后再删掉原Port 22 端口行。
修改完成后保存。
3、重启SSH服务器
重启SSH服务器命令:
如果没有systemctl的话可以执行:
1
| /etc/init.d/sshd restart
|
或
如果没有报错的话就生效了,可以
或
查看一下端口。
4、防火墙、安全组规则设置
iptables添加SSH新端口规则:
1
| iptables -A INPUT -p tcp --dport 3322 -j ACCEPT
|
然后保存iptables规则
firewalld添加SSH新端口规则:
1
| firewall-cmd --permanent --zone=public --add-port=3322/tcp
|
阿里云之类的安全组规则添加SSH新端口规则:
阿里云之类的有安全组之类设置的云服务器一定要在安全组规则里将新端口添加到“入方向”的允许规则。
转载文献
VPS侦探:CentOS/Debian/Ubuntu Linux修改SSH默认22端口