VMware Workstation Pro中安装、配置Debian12。
基础环境配置信息
| 软件 | 版本 |
|---|---|
OS | Windows 11 |
VMware Workstation Pro | 17.6.1 build-24319023 |
Debian | 12.08 LTS |
MobaXterm | Professional Edition v24.0 |
前置条件
VMware Workstation Pro已经安装完成。debian-12.8.0-amd64-netinst.iso文件已经下载至本地磁盘。
debian-12.8.0-amd64-netinst.iso下载地址为https://mirrors.tuna.tsinghua.edu.cn/debian-cd/12.8.0/amd64/iso-cd/debian-12.8.0-amd64-netinst.iso
MobaXterm已经安装完成。
虚拟机创建
- 启动
VMware Workstation Pro,选择菜单文件->创建虚拟机:
在创建虚拟机过程中,出于简化篇幅的目的,对于各步骤中保持默认选项的,不在本文档中给出,直接
"下一步"即可。
- 在
安装客户机操作系统页面,选择稍后安装操作系统(S):
- 在
选择客户机操作系统页面,选择Debian 12.x 64位:
- 在
命名虚拟机页面,输入虚拟机名称Debian12.08,该名称主要便于用户记忆,可根据需求自行改为所需名称:
- 后续步骤均采用
VMware默认配置即可。创建完成后,库中会显示创建的Debian12.08虚拟机,点击编辑虚拟机设置:
- 设置虚拟机的
ISO映像文件,通过浏览按钮选择之前下载好的debian-12.8.0-amd64-netinst.iso文件:
- 为虚拟机设置禁用侧通道缓解,在
选项页面,高级->为启用了Hyper-V的主机禁用侧通道缓解(S):
该步骤为可选步骤。
Debian安装
- 点击
开启此虚拟机,启动之前创建的虚拟机:
- 在开机引导菜单中,选择第二项
Install:
在安装过程中,出于简化篇幅的目的,对于各步骤中保持默认选项的,不在本文档中给出,直接回车即可。
- 在
Set up users and passwords页面设置Root password,输入密码123456:
在命令行控制台下,可以通过
Tab键在各按钮与输入框间跳转。对于复选框,以按空格键进行选中或取消。
- 在
Set up users and passwords页面设置Re-enter password to verify,再次验证输入密码123456:
- 在
Set up users and passwords页面设置Full name for the new user,输入用户名rz:
- 在
Set up users and passwords页面设置Choose a password for the new user,输入刚创建的用户rz密码,为方便记忆,均设置为123456:
- 在
Set up users and passwords页面设置Re-enter password to verify,再次输入用户rz密码123456:
- 在分区
Partition disks页面,选择写入磁盘:
- 在
Configure the package manager页面,Debian的安装源国家选择China:
- 在
Configure the package manager页面,Debian安装源选择为清华安装源:
用户也可以根据实际情况选择其他安装源。
- 在
Configure the package manager页面,HTTP proxy information代理不需要设置,直接Tab键选择Continue:
- 在
Software selection页面,设置安装的软件,本系统采用最小化安装,因此仅需要SSH server与standard system utilities两个软件包即可:
- 在
Install the GRUB boot loader页面,设置boot loader安装位置为/dev/sda:
- 最后,重启系统:
- 重启后,在重启动引导页面,默认第一项即可:
- 系统启动后,使用之前创建的用户
rz,密码123456登录:
- 至此,系统安装成功。切换到
root用户,使用/sbin/poweroff命令关机:
- 点击菜单
虚拟机(M)->快照(N)->拍摄快照(T),对刚安装完成的虚拟机拍摄快照:
- 输入快照名称
系统安装完成,用户可以根据需求改为自己所需的快照名称:
- 拍摄快照之后,在虚拟机详细信息中可以显示出快照为
系统安装完成:
远程登录
- 启动
Debian12.08虚拟机,并登录。使用ip addr命令查看虚拟机的IP地址:
192.168.152.141为当前虚拟机的IP地址。
- 建议使用
PowerShell自带的SSH客户端、MobaXterm等SSH工具远程登录进行使用。在Windows 11中,可以使用PowerShell进行远程登录:
> ssh rz@192.168.152.141
The authenticity of host '192.168.152.141 (192.168.152.141)' can't be established.
ED25519 key fingerprint is SHA256:p9XBcIdiRbiFNWOvlCCoX7p9agH41B3trpeMfJW9hZk.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.152.141' (ED25519) to the list of known hosts.
rz@192.168.152.141's password:
Linux debian 6.1.0-28-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.119-1 (2024-11-22) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Dec 25 08:31:03 2024
- 也可以使用
MobaXterm登录,启动MobaXterm,点击MobaXterm的工具栏Session:
- 输入虚拟机
Debian12.08的IP地址192.168.152.141,用户名rz:
- 输入
rz的密码123456,登录完成:
vim安装
- Debian12最小化安装后,需要单独安装
vim:
rz@debian:~$ su
Password:
root@debian:/home/rz# apt update
root@debian:/home/rz# apt install vim
root@debian:/home/rz# exit
exit
rz@debian:~$
sudo配置
- 安装
sudo:
rz@debian:~$ su
Password:
root@debian:/home/rz# apt install sudo
- 配置
sudo,将普通用户rz加入到sudo组,使其具备sudo组权限:
root@debian:/home/rz# /sbin/usermod -aG sudo rz
root@debian:/home/rz# groups rz
rz : rz cdrom floppy sudo audio dip video plugdev users netdev
root@debian:/home/rz# exit
exit
rz@debian:~$ newgrp sudo
静态IP配置
- 使用
sudo vim命令编辑网络配置文件/etc/network/interfaces:
# 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
allow-hotplug ens33
# iface ens33 inet dhcp
iface ens33 inet static
address 192.168.152.3/24
network 192.168.152.0
broadcast 192.168.152.255
gateway 192.168.152.2
- 设置静态IP地址为
192.168.152.3;- 在
VMware中,默认路由一般最后一位为2;
- 重启网络服务:
rz@debian:~$ sudo systemctl restart networking.service
rz@debian:~$ sudo systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; preset: en>
Active: active (exited) since Wed 2024-12-25 08:59:48 EST; 27s ago
Docs: man:interfaces(5)
Process: 8267 ExecStart=/sbin/ifup -a --read-environment (code=exited, statu>
Process: 8292 ExecStart=/bin/sh -c if [ -f /run/network/restart-hotplug ]; t>
Main PID: 8292 (code=exited, status=0/SUCCESS)
CPU: 44ms
Dec 25 08:59:48 debian systemd[1]: Starting networking.service - Raise network i>
Dec 25 08:59:48 debian systemd[1]: Finished networking.service - Raise network i>
按
q键退出查看服务状态。 若配置的静态IP地址与当前IP地址不一致时,重启network服务(networking.service)时,已经登录的SSH用户会掉线。重新使用新静态IP地址进行登录即可。
bash配置
~目录配置,使用vim编辑~/.bashrc:
...
90 │ # some more ls aliases
91 │ alias ll='ls -l'
92 │ alias la='ls -A'
93 │ alias l='ls -CF'
...
删除
91-93行的注释
- 使用
sudo vim命令编辑/etc/bash.bashrc,启用bash命令补全功能:
...
34 │ # enable bash completion in interactive shells
35 │ if ! shopt -oq posix; then
36 │ if [ -f /usr/share/bash-completion/bash_completion ]; then
37 │ . /usr/share/bash-completion/bash_completion
38 │ elif [ -f /etc/bash_completion ]; then
39 │ . /etc/bash_completion
40 │ fi
41 │ fi
...
删除
35-41行的注释
- 加载配置,使生效:
rz@debian:~$ source /etc/bash.bashrc
rz@debian:~$ source .bashrc
安装源配置
- 因为在实验与演示环境中,不需要考虑安全更新,同样也不考虑从源代码进行编辑,为加速每次安装软件与更新速度,注释掉安全源与源码源。使用
sudo vim命令编辑/etc/apt/sources.list:
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main non-free-firmware
# deb http://security.debian.org/debian-security bookworm-security main non-free-firmware
# deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main non-free-firmware
修改完之后,需要执行
sudo apt update更新可用软件列表。
sshd服务允许root远程登录
- 修改
sshd服务配置文件,使用sudo vim命令编辑/etc/ssh/sshd_config:
#PermitRootLogin prohibit-password
PermitRootLogin yes
- 重启
ssh服务:
rz@debian:~$ sudo systemctl daemon-reload
rz@debian:~$ sudo systemctl restart sshd
rz@debian:~$ sudo systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-12-25 21:51:31 EST; 12s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 6721 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 6723 (sshd)
Tasks: 1 (limit: 2264)
Memory: 1.4M
CPU: 23ms
CGroup: /system.slice/ssh.service
└─6723 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Dec 25 21:51:31 debian systemd[1]: Starting ssh.service - OpenBSD Secure Shell s>
Dec 25 21:51:31 debian sshd[6723]: Server listening on 0.0.0.0 port 22.
Dec 25 21:51:31 debian sshd[6723]: Server listening on :: port 22.
Dec 25 21:51:31 debian systemd[1]: Started ssh.service - OpenBSD Secure Shell se>
主机名配置
- 配置主机名,此处设置主机名为
debase,域名为debase.rz:
rz@debian:~$ sudo hostnamectl set-hostname debase --static
- 使用
sudo vim命令编辑/etc/hosts文件,修改内容如下:
127.0.0.1 localhost
127.0.1.1 debase
192.168.152.3 debase.rz
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
使用
sudo vim /etc/hosts时,会给出警告信息:sudo: unable to resolve host hub: Name or service not known,是由于此时/etc/hosts内容未做同步变更造成的。
- 重新登录,使主机名生效。
- 使用
ping命令,验证主机名与域名:
rz@debase:~$ ping debase
PING debase (127.0.1.1) 56(84) bytes of data.
64 bytes from debase (127.0.1.1): icmp_seq=1 ttl=64 time=0.013 ms
64 bytes from debase (127.0.1.1): icmp_seq=2 ttl=64 time=0.034 ms
^C
--- debase ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1024ms
rtt min/avg/max/mdev = 0.013/0.023/0.034/0.010 ms
rz@debase:~$ ping debase.rz
PING debase.rz (192.168.152.3) 56(84) bytes of data.
64 bytes from debase.rz (192.168.152.3): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from debase.rz (192.168.152.3): icmp_seq=2 ttl=64 time=0.025 ms
^C
--- debase.rz ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1029ms
rtt min/avg/max/mdev = 0.017/0.021/0.025/0.004 ms
使用
Ctrl+C中止ping命令。
常用工具batcat、tree、curl
- 安装
batcat与tree:
rz@debase:~$ sudo apt update
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
rz@debase:~$ sudo apt install bat tree curl
设置系统时区
timedatectl是一个现代的命令行工具,用于查询和更改系统时间和日期设置。设置时区为Asia/Shanghai:
rz@debase:~$ timedatectl
Local time: Wed 2024-12-25 22:00:36 EST
Universal time: Thu 2024-12-26 03:00:36 UTC
RTC time: Thu 2024-12-26 03:00:36
Time zone: US/Eastern (EST, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
rz@debase:~$ sudo timedatectl set-timezone Asia/Shanghai
rz@debase:~$ timedatectl
Local time: Thu 2024-12-26 11:01:07 CST
Universal time: Thu 2024-12-26 03:01:07 UTC
RTC time: Thu 2024-12-26 03:01:07
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
history配置记录命令执行时间戳
- 在Linux系统中,默认情况下,Bash shell(以及其他类似的shell,如Zsh)会记录输入的命令历史。然而,这些历史记录默认情况下并不会包含命令执行的时间戳。
- 编辑
~/.bashrc文件,添加如下内容到文件尾:
export HISTTIMEFORMAT="%F %T "
将
HISTTIMEFORMAT环境变量设置为包含日期和时间(格式为YYYY-MM-DD HH:MM:SS)的字符串。
- 重新加载配置文件:
rz@debase:~$ source .bashrc
- 使用
history命令:
rz@debase:~$ tree ~/
/home/rz/
0 directories, 0 files
rz@debase:~$ history
...
53 2024-12-26 11:02:57 tree ~/
54 2024-12-26 11:03:08 history
每条命令前面有执行时间戳