系统安装
类型为EXT4格式,200M给/boot,其余容量都给根目录
Debian不创建root密码,这样就能自带sudo
系统优化
软件源替换
Centos 7.9
yum install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
Debian 12.5
sudo apt install apt-transport-https ca-certificates -y
sudo nano /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
sudo apt-get update
Ubuntu 22.04.4
sudo nano /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
软件安装
Centos 7.9
yum install vim nano tcpdump tree
Debian 12.5
sudo apt-get install vim curl tcpdump tree -y
Ubuntu 22.04.4
apt-get install tree -y
账号设置
添加一个admin用户,属于admin组,并且具有无密码的sudo权限。
useradd -m -s /bin/bash admin&&passwd -d admin
删除root用户密码
passwd -d root
sudo权限设置
# 方法一
echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# 方法二
usermod -aG sudo admin
提示如果添加了临时用户记得删除
userdel -r <用户名>
SSH设置
cat <<EOF >> /etc/ssh/sshd_config
# 禁用了DNS反向解析
UseDNS no
# 记录SSH日志消息
SyslogFacility AUTHPRIV
# 允许root用户登入
PermitRootLogin yes
# 允许免密登入
PermitEmptyPasswords yes
EOF
?>较新的操作系统需要添加以下内容
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
GURP设置
Centos 7.9
按需修改
vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto net.ifnames=0 console=tty0 console=ttyS0,115200n8"
grub2-mkconfig -o /boot/grub2/grub.cfg
Debian 12.5
按需修改
vim /etc/default/grub
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200n8 consoleblank=0 vga=792 net.ifnames=0 noibrs iommu=pt crashkernel=0M-1G:0M,1G-4G:160M,4G-8G:192M,8G-128G:384M,128G-:512M crash_kexec_post_notifiers nvme_core.io_timeout=4294967295 nvme_core.admin_timeout=4294967295"
update-grub
主机名修改
修改为自己的发行版本即可。
开机提示
服务器信息显示(个人优化)
在Centos的系统中,/etc/issue
中的内容会在用户登入前显示,/etc/motd
中的内容会在用户成功登入后显示。
cd ~&&touch hello.sh&&chmod +x hello.sh
/etc/issue
中的内容会在用户登入前显示,/etc/motd
中的内容会在用户成功登入后显示。
?>注意修改默认信息
#!/bin/bash
truncate -s 0 /etc/issue
truncate -s 0 /etc/motd
# 获取物理网卡 IPV4地址、子网掩码、网卡名称
ipv4=$(ip addr | grep -e "scope global" -e "scope link" | grep -v inet6 | grep -e eth -e ens | awk '{print("\033[34m|\033[0m\033[32m",$NF,"\t->",$2,"\033[0m")}')
if [ -z "$ipv4" ]; then
ipv4="\033[34m|\033[0m\033[32m Network not connected \033[0m"
fi
# 获取发行版名称和版本
sys_name=`cat /etc/os-release | grep PRETTY_NAME | awk -F '=' '{print($2)}' | sed 's/"//g'`
# 间隔符
t1="\033[34m+----------------------------\033[0m"
t2="\033[34m|\033[0m\033[32m"
t3="\033[0m"
# 自定义信息
info="
$t1
$t2 $sys_name $t3
$t1
$t2 Default User: $t3
$t2 -> admin/NULL$t3
$t2 -> root/NULL $t3
$t1
$ipv4
$t1
"
# /etc/issue 默认存在的信息
issue_def="\S
Kernel \r on an \m"
# /etc/motd 默认存在的信息
#motd_def=""
echo "$issue_def" > /etc/issue
echo -e "$info" >> /etc/issue
#echo "$motd_def" > /etc/motd
echo -e "$info" >> /etc/motd
通过添加自定义服务,并且设置为开机启动,来运行脚本。
vim /etc/systemd/system/hello.service
适用于Centos
[Unit]
Description=Welcome information
After=NetworkManager-wait-online.service
[Service]
Type=oneshot
User=root
ExecStart=/root/hello.sh
[Install]
WantedBy=multi-user.target
适用于Ubuntu
[Unit]
Description=Welcome information
After=networking.service
[Service]
Type=oneshot
User=root
ExecStart=/root/hello.sh
[Install]
WantedBy=multi-user.target
设置服务开启启动
systemctl enable hello.service
?>请先手动执行一次脚本
网络
Centos7.9
设置网卡自启动
nmcli connection modify eth0 connection.autoconnect yes
Debian 12.5
先查看网卡名称
ip add
编辑配置文件
sudo nano /etc/network/interfaces
添加以下内容
动态IP
auto ens3
iface ens3 inet dhcp
日志清除
echo "" > /var/log/lastlog && echo "" > /var/log/wtmp && echo "" > /var/log/btmp
使用建议
在PnetLab平台中,如果使用HTML5终端,建议使用SSH控制台进行操作,例如主控制台选择SSH,辅助控制台选择VNC(该控制台可以看到开机过程,首次开机使用该控制台)。