Vmware 17 创建 Debian 11 服务器

飞花不语 / 2023-05-18 / 原文

第一步 宿主机断网

创建Debian虚拟服务器时,首先断开宿主机的网络,避免创建时自动更新软件导致长时间等待,无法进行后续操作


第二步 自定义创建虚拟服务器(最小化安装,之后缺什么安装什么,以便明确知道目标软件是否需要额外的依赖项)

详细过程略。注意点:安装流程中倒数第二步,选择安装软件时,取消全部已选中的,然后选择ssh,最后回车确定。


第三步 使用超级管理员root登入系统,修改ssh配置文件sshd_config的属性值PermitRootLogin,允许root用户登录。最后使用Xshell登录进行操作

vi /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes

第四步 更换apt源为国内源

(1)清空apt配置文件内容,粘贴国内源地址至配置文件
vi /etc/apt/sources.list

debian 11 国内源

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
(2)更新apt索引及系统软件包
apt update && apt upgrade -y

第五步 安装基础软件vim、ufw

(1)安装软件
apt install vim ufw -y
(2)修改vim配置文件
vim /usr/share/vim/vim82/defaults.vim
set mouse=a   -->   set mouse-=a
(3)启用ufw
ufw enable
(3)修改防火墙策略,禁用所有的流入流量,并开放ssh端口
ufw default deny && ufw allow 22/tcp
(4)查看防火墙策略
ufw status verbose

第六步 修改grub引导等待时间为0

(1)修改grub配置文件中的GRUB_TIMEOUT属性值
vim /etc/default/grub
GRUB_TIMEOUT=5   -->   GRUB_TIMEOUT=0
(2)更新grub配置

如果提示找不到该命令,则查看系统环境变量是否包含路径 /usr/sbin

update-grub2

第七步 删除创建虚拟服务器时引导创建的系统管理员world(可能是其他名称,根据你创建的管理员角色来操作)

(1)删除world主目录及角色
rm -rf /home/world && userdel world
(2)查看是否已被删除
id world

第八步 配置静态IP地址

  • (1)编辑配置文件 /etc/network/interfaces

    vi /etc/network/interfaces
    
  • (2)修改后的配置如下所示

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    # 配置的网卡名称需要与实际的网卡名称一致
    # ip address 查看网卡名称及属性
    # 修改完成后重启系统,以便配置生效
    allow-hotplug ens32
    iface ens32 inet static #dhcp #注释掉动态分配,修改为静态
    address 192.168.108.100 #IP地址
    netmask 255.255.255.0   #子网掩码
    gateway 192.168.108.2   #网关
    
    #注意:复制粘贴内容至配置文件时应该删除中文注释内容