在安装完新系统后,往往需要做系统初始化,配置或修改一些必要配置

关闭防火墙

# 关闭
sudo ufw disable
# 禁用服务
sudo systemctl stop ufw && sudo systemctl disable ufw

配置时间同步

# 配置NTP同步地址为`ntp.aliyun.com`
sudo vim /etc/systemd/timesyncd.conf
# [Time]
# NTP=ntp.aliyun.com
sudo timedatectl set-timezone Asia/Shanghai
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
sudo systemctl daemon-reload
sudo systemctl restart systemd-timesyncd

优化ssh连接,提高连接速度

sudo sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sudo systemctl  restart sshd.service

更换apt软件源为国内源,提高包下载速度

# 备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
# 使用腾讯源,不同源文件可参考 http://mirrors.cloud.tencent.com/repo/
sudo wget -O /etc/apt/sources.list http://mirrors.cloud.tencent.com/repo/ubuntu20_sources.list
# 更新
sudo apt-get clean all
sudo apt-get update

安装常用软件包

sudo apt-get install -y htop net-tools openssl

修改ssh默认端口

sudo vi /etc/ssh/sshd_config

修改#Port 22行为Port 指定端口,保存后sudo systemctl restart sshd或重启机器即可

重启机器

sudo reboot

开启root账号(选配)

# 1. 设置root账号密码
sudo passwd root
# 2. 开启ssh允许root账号使用密码登录
sudo vim /etc/ssh/sshd_config
# 将# PermitRootLogin prohibit-password行 改为 PermitRootLogin yes
PermitRootLogin yes

修改完重启ssh服务或重启机器即可。不使用root账号有利于安全,但是执行高权限命令时需要前边带sudo,请根据实际情况开启