- Published on
Debian
- Authors

- Name
- MissTree
学习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.service | masked | enabled |
| avahi-daemon.socket | enabled | enabled |
| cups.socket | enabled | enabled |
| saned.socket | disabled | enabled |
| systemd-networkd.socket | disabled | enabled |
| reboot.target | disabled | enabled |
| remote-cryptsetup.target | disabled | enabled |
| remote-fs.target | enabled | enabled |
| remote-veritysetup.target | disabled | enabled |
| anacron.timer | enabled | enabled |
| apt-daily-upgrade.timer | enabled | enabled |
| apt-daily.timer | enabled | enabled |
| dpkg-db-backup.timer | enabled | enabled |
| e2scrub_all.timer | enabled | enabled |
| fstrim.timer | enabled | enabled |
| fwupd-refresh.timer | enabled | enabled |
| logrotate.timer | enabled | enabled |
| man-db.timer | enabled | enabled |
笔记本合上断链
在使用家里的笔记本作为服务器时,合上笔记本合上盖子,会发现网线断链,导致无法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文件,取消以下注释ClientAliveIntervalClientAliveCountMax,修改,然后保存退出。 执行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目录下自己建立的文件不是以中文的就不会有影响