Published on

Debian

Authors
  • avatar
    Name
    MissTree
    Twitter

学习Debian遇到的坑点

登录不了 root 账户

在安装 Debian 12 的时候默认要创建一个用户。在第一次进入默认系统的时候,只能登录创建的用户,登录root账户会报密码错误(密码是正确的),而在一些安装软件或者编辑文件的时候久需要到root权限,所以。。。

  • 在系统开启前 通过 上、下键选择 Advanced options for Debian GNU/Linux recovery mode 进入系统,此时进入的是控制台终端,而不是可视化界面

  • 执行 vi /etc/gdm3/daemon.conf 编辑文件,在[security]下添加AllowRoot=true;

    # code
    [security]
    AllowRoot=true
    
    
  • 执行 vi /etc/pam.d/gdm-password 编辑文件,把auth required pam_succeed_if.so user != root quiet_success这一行注释掉

    # code
    # auth   required        pam_succeed_if.so user != root quiet_success
    # code
    
  • 执行vi /etc/ssh/sshd_config ,ssh 远程链接设置,找到PermitRootLogin这一行,并将其修改为yes,如果没有就添加一行。最后执行 systemctl restart sshd

    # code
    PermitRootLogin yes
    # code
    

要执行后面的ssh是因为好像用root登录没办法启用终端,每次启动都自动关掉


安装时没有设置安装外部网络安装源

  • ping www.baidu.com 查看网络情况是否正常

  • 设置安装源数据 vim /etc/apt/sources.list 选一个就好,然后 sudo apt update

    ## 阿里云镜像源
    deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free
    deb-src http://mirrors.aliyun.com/debian/ bookworm main contrib non-free
    deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
    deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
    deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free
    deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free
    deb http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free
    deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free
    
    

清华源

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security main
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security main
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free

腾讯源

deb https://mirrors.tencent.com/debian/ bookworm main contrib non-free
deb-src https://mirrors.tencent.com/debian/ bookworm main contrib non-free
deb https://mirrors.tencent.com/debian-security/ bookworm-security main
deb-src https://mirrors.tencent.com/debian-security/ bookworm-security main
deb https://mirrors.tencent.com/debian/ bookworm-updates main contrib non-free
deb-src https://mirrors.tencent.com/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tencent.com/debian/ bookworm-backports main contrib non-free
deb-src https://mirrors.tencent.com/debian/ bookworm-backports main contrib non-free

  • 测试安装如 :sudo apt install wget

取消部分开机启动项

其实使用debian就是基本默认将电脑作为服务主机了,所以很多服务都不需要开机启动,下面是默认的开机启动项:

启动项名称描述是否可以禁用
run-vmblock\x2dfuse.mount可能与虚拟机相关的块设备挂载有关。如果系统不是运行在虚拟机环境或者不需要特定的虚拟机块设备挂载功能,可以考虑禁用。用于在系统启动时挂载与虚拟机相关的存储块设备,确保虚拟机能够正常访问存储资源。enabled
cups.path管理打印机和打印任务true
accounts-daemon.service用于管理用户账户相关的操作,如用户登录、密码验证等,不可禁用false
alsa-utils.service主要用于音频设备的管理和配置。在屏蔽状态下正常情况开机时不会启动。true
anacron.service用于在系统启动后定期执行一些任务,这些任务通常是被cron服务遗漏的(例如系统在cron任务计划时间内关机)。对于一些需要定期执行但对时间精度要求不高的任务很有用,如系统日志清理等。false
apache-htcacheclean.service主要用于清理Apache服务器的缓存。如果系统不运行Apache网页服务,可保持禁用状态enabled
apache-htcacheclean@.service与apache - htcacheclean.service类似,是Apache缓存清理服务的实例化模板enabled
apache2.service用于启动Apache2网页服务器。如果系统不需要提供网页服务,可考虑禁用enabled
apache2@.service这是Apache2服务的模板实例。如果系统不需要提供网页服务,可保持禁用状态。enabled
apparmor.service是一种 Linux 安全模块,用于限制程序的功能,提供应用程序级别的安全防护。enabled
avahi-daemon.service实现零配置网络服务发现协议,用于在本地网络中发现设备和服务。true
bluetooth.service用于管理系统的蓝牙连接。true
console-setup.service用于设置控制台相关的参数,如终端字体、颜色等。false
containerd.service是一个容器运行时,用于管理容器的生命周期,如启动、停止和删除容器等。false
cron.service用于在固定的时间间隔执行命令或脚本,是系统中实现定时任务的重要服务,一般不建议禁用。false
cryptdisks-early.service与加密磁盘的早期初始化有关。true
cryptdisks.service用于管理加密磁盘的服务。在屏蔽状态下正常情况开机时不会启动。true
cups-browsed.service与打印系统(CUPS)相关,用于在网络中浏览可用的打印机。false
cups.service是打印系统(CUPS)的核心服务,用于管理打印机和打印任务。true
docker.service用于启动Docker容器平台。false
e2scrub_reap.service与ext2/ext3/ext4文件系统的错误检查和修复后的清理工作有关。false
getty@.service用于在终端启动getty进程,提供登录提示符,是用户登录系统的重要接口。false
hwclock.service用于硬件时钟的管理,来同步时间或者有其他时间同步方式enabled
ifupdown-wait-online.service与网络接口的启动和等待网络连接上线有关。false
keyboard-setup.service用于设置键盘相关的参数,如键盘布局等。false
low-memory-monitor.service用于监控系统内存状态,当内存较低时采取一些措施(如释放缓存等)false
odemManager.service用于管理调制解调器设备。enabled
networking.service用于管理系统的网络配置和连接。false
NetworkManager-dispatcher.service是NetworkManager的一个附属服务,用于在网络状态变化时执行一些脚本或操作。false
NetworkManager-wait-online.service用于等待网络连接上线,与NetworkManager相关。false
NetworkManager.service是一个用于管理网络连接的工具,提供了更灵活的网络配置方式,包括有线和无线网络。false
nftables.service用于网络数据包过滤,类似于iptables。false
open-vm-tools.service与虚拟机相关的工具服务,用于在虚拟机环境中提供一些便利功能,如共享文件夹、鼠标集成等。true
power-profiles-daemon.service用于管理系统的电源配置文件,如节能模式、高性能模式等enabled
rc.service在传统的SysV初始化系统中有重要作用,在现代的systemd系统中已被替代true
rcS.service与rc.service类似,在传统的SysV初始化系统中有作用,在现代systemd系统中已被替代true
rtkit-daemon.service用于管理实时进程的优先级。true
saned.service用于扫描文档管理相关的功能。enabled
saned@.service与saned.service类似,可能是通过间接方式关联到扫描文档管理功能。enabled
serial-getty@.service用于串口终端相关的功能。enabled
speech-dispatcherd.service用于语音相关的功能,如语音合成或语音命令等。true
ssh.service用于启动SSH(Secure Shell)服务,允许远程登录系统。false
sudo.service在屏蔽状态下正常情况开机时不会启动,主要用于管理sudo命令的权限相关功能false
switcheroo-control.service可能与系统的设备切换(如显卡切换等)有关。true
systemd-fsck-root.service用于在系统运行时检查根文件系统的一致性。enabled-runtime enabled
systemd-network-generator.service用于生成网络配置相关的文件。enabled
systemd-networkd-wait-online@.service与网络连接等待上线相关,是systemd - networkd的一部分enabled
systemd-networkd.service用于管理网络配置和连接的systemd自带网络服务。enabled
systemd-pstore.service用于管理持久存储(pstore)相关的内容,如系统崩溃信息等false
systemd-remount-fs.service用于在系统运行时重新挂载文件系统。enabled-runtime false
systemd-sysext.service与系统扩展(sysext)相关。如果系统没有使用系统扩展功能,可以保持禁用状态。true
systemd-timesyncd.service用于系统时间同步。false
udisks2.service用于自动检测和挂载可移动存储设备(如 U 盘、移动硬盘)。true
upower.service主要用于电源管理相关的功能,如电池状态监测等。true
vgauth.service可能与卷组认证(vgauth)相关,用于存储系统中卷组的安全认证等功能。enabled
wpa_supplicant-nl80211@.service主要用于无线网络(nl80211相关部分)的认证连接。enabled
wpa_supplicant-wired@.service主要用于有线网络的认证连接false
wpa_supplicant.service用于无线网络和有线网络的认证连接。false
wpa_supplicant@.service这是wpa_supplicant服务的模板实例。enabled
x11-common.servicemaskedenabled
avahi-daemon.socketenabledenabled
cups.socketenabledenabled
saned.socketdisabledenabled
systemd-networkd.socketdisabledenabled
reboot.targetdisabledenabled
remote-cryptsetup.targetdisabledenabled
remote-fs.targetenabledenabled
remote-veritysetup.targetdisabledenabled
anacron.timerenabledenabled
apt-daily-upgrade.timerenabledenabled
apt-daily.timerenabledenabled
dpkg-db-backup.timerenabledenabled
e2scrub_all.timerenabledenabled
fstrim.timerenabledenabled
fwupd-refresh.timerenabledenabled
logrotate.timerenabledenabled
man-db.timerenabledenabled

笔记本合上断链

在使用家里的笔记本作为服务器时,合上笔记本合上盖子,会发现网线断链,导致无法ssh链接。解决办法:

# 安装OpenSSH服务器
sudo apt update
sudo apt install openssh-server
# 启动并启用SSH服务
sudo systemctl start ssh
sudo systemctl enable ssh
  • 编辑 /etc/systemd/logind.conf 文件,在文件末尾添加 HandleLidSwitch=ignore ,然后保存退出。

    • ignore:表示当笔记本合上盖子时,系统不执行任何特殊操作,不会进入睡眠或其他可能导致网络连接中断的状态。
    • block:希望在合上盖子时仍然能够正常使用笔记本的其他功能,这样系统会在合上盖子时锁定屏幕,但不会断开网络连接。
    HandleLidSwitch=ignore
    HandleLidSwitchDocked=ignore
    IdleAction=ignore
    # 重启服务
    sudo systemctl restart systemd-logind
    
  • 执行 systemctl restart systemd-logind 命令,重启 systemd-logind 服务。

  • 编辑 /etc/ssh/sshd_config 文件,取消以下注释 ClientAliveInterval ClientAliveCountMax,修改,然后保存退出。 执行 sudo systemctl restart sshd 重启ssh服务

    # code
    # 保持链接 10分钟
    ClientAliveInterval 600
    # 断连链接 3次
    ClientAliveCountMax 3  
    # code
    
  • 禁用息屏

    sudo apt install xserver-xorg
    
    sudo nano /etc/X11/xorg.conf.d/10-monitor.conf
    # 添加以下内容
    Section "ServerFlags"
        Option "BlankTime" "0"
        Option "StandbyTime" "0"
        Option "SuspendTime" "0"
        Option "OffTime" "0"
    EndSection
    
  • 禁用睡眠和休眠

    sudo nano /etc/systemd/sleep.conf
    # 添加或修改以下行
    AllowSuspend=no
    AllowHibernation=no
    AllowHybridSleep=no
    
    
  • 设置网络唤醒(可选)

    # 安装插件
    sudo apt install ethtool
    # enp7s0 为有线接口名称,无线的使用 ip addr下的无线接口(例如:wlp6s0)
    sudo ethtool -s enp7s0 wol g
    # 验证是否成功
    ethtool enp7s0
    # 返回结果
    Supports Wake-on: pumbg
    Wake-on: g
    

设置永久生效

# 方式 1
sudo nano /etc/rc.local
# 在 exit 0 之前添加
ethtool -s enp7s0 wol g
sudo chmod +x /etc/rc.local


# 方法 2:使用 systemd 服务
sudo nano /etc/systemd/system/wol.service
# 添加以下内容
[Unit]
Description=Enable Wake-on-LAN for enp0s3

[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s enp0s3 wol g

[Install]
WantedBy=multi-user.target
# 保存并退出,然后启用服务
sudo systemctl enable wol.service
sudo systemctl start wol.service

在使用WiFi模式会出现断链的情况,使用有线模式不会出现断链的情况,下面含解决方式。

wifi链接

使用 GNOME 桌面环境时,wifi 链接会出现问题,无法链接。

  • 编辑 /etc/NetworkManager/NetworkManager.conf 文件,在文件末尾添加 [device]wifi.scan-rand-mac-address=no ,然后保存退出。
  • 执行 sudo systemctl restart NetworkManager 重启 NetworkManager 服务。

使用 GNOME Xorg 桌面环境时,wifi 可以直接桌面可视化链接,但是在合上笔记本的时候会出现断链的情况,要在电池设置不休眠,使WiFi保持连接。

GNOME Xorg 桌面建议:在第一次进入的时候不要修改桌面配置,否则ssh进入到 root 目录后会以编码显示名称,虽然对操作影响不大,因为root目录下自己建立的文件不是以中文的就不会有影响