Debian自用设置
用于系统重装后的快速设置。
1 用户
1.1 新建用户
-d
: 指定用户文件夹,-m
: 如果文件夹不存在就新建,-s
: 指定用户登录时使用指定shell
。1
sudo useradd -d /home/username -m -s /bin/bash username
如有必要递归更改用户文件夹的权限:sudo chown -R username:usergroup /home/username
修改用户密码:
1
sudo passwd username
检查所有用户
cat /etc/passwd
, 检查所有用户组cat /etc/group
。
1.2 用户加入sudoers
更改
sudoers
文件权限:1
sudo chmod 644 /etc/sudoers
编辑
/etc/sudoers
, 在root ALL=(ALL:ALL) ALL
下添加一行你的用户名 ALL=(ALL:ALL) ALL
, 比如:1 2
root ALL=(ALL:ALL) ALL username ALL=(ALL:ALL) ALL
1.3 设置root用户的密码
|
|
2 自定义终端
/etc/envirnoment
与shell
无关, 所以无法使用脚本或通配符展开。此文件仅接受variable=value
键值对格式。
其他文件的加载顺序: /etc/profile
>/etc/bash.bashrc
>~/.profile
=~/.bash_profile
>~/.bashrc
aliases
添加到系统级环境变量配置文件/etc/profile
或/etc/bash.bashrc
中, 对机器上的所有用户生效。2.1 alias
创建~/.bash_aliases
文件, 输入以下内容:
|
|
在~/.bashrc
中添加以下内容以加载~/.bash_aliases
文件:
|
|
手动source ~/.bashrc
以在当前终端生效, 或者在~/.profile
中添加:
|
|
这样每次用户登录时, ~/.bashrc
文件会被自动加载生效。
2.2 bash提示符颜色
参考自定义bash提示符颜色。效果如下:
普通用户:
root用户:
2.3 ls -l时间格式
在环境变量配置文件中添加:
|
|
输出示例:
|
|
3 修改SSH设置
sudo systemctl status ssh.service
确定设备的SSH服务没有运行即可。参考设置 SSH 通过密钥登录, 将客户机的公钥内容追加到服务器
~/.ssh/authorized_keys
文件中, 再更改权限:1 2
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
更改
/etc/ssh/sshd_config
文件内容:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Include /etc/ssh/sshd_config.d/*.conf Port 12345 # SSH端口号 LoginGraceTime 3s # 若用户未成功登录, 服务器将在此时间后断开连接 MaxAuthTries 4 # 每个连接最大允许的认证次数 MaxSessions 4 # 最大允许保持多少个未认证的连接 PermitRootLogin yes # 允许root用户登录 AuthenticationMethods publickey # 指定登录方式为使用公钥验证 PubkeyAuthentication yes # 允许使用公钥验证登录 PasswordAuthentication no # 禁用密码登录 PermitEmptyPasswords no # 禁用空密码登录 ChallengeResponseAuthentication no # 双重认证需要 UsePAM no # 插入式验证模块, 比如双重认证 PrintLastLog yes # 显示上次登录的信息 TCPKeepAlive yes # 确保联机正常, server和client中的任何一端离线, 马上断开 X11Forwarding no # 禁用远程执行GUI程序支持 PrintMotd no # 禁用登录后提示信息 Banner none # 禁用远程登录后提示信息 Compression no # 网速快, 没必要压缩 ClientAliveInterval 60 # 服务器没有从客户端收到消息后的超时时间 ClientAliveCountMax 3 # 客户端超时次数 UseDNS no # 禁用反向DNS解析 AcceptEnv LANG LC_* # 允许客户端传递区域设置环境变量 Subsystem sftp /usr/lib/openssh/sftp-server # sftp AllowUsers root username # 允许登录的用户名
ClientAliveInterval
乘以ClientAliveCountMax
, 即超时60s*3=180s后ssh断开连接。- 如果仍然有登录后提示, 可以清空相应文件
> /etc/motd
。
重启SSH服务:
1 2 3
sudo systemctl restart ssh.service 或者 /etc/init.d/ssh restart
在防火墙关闭22端口, 放行自定义的SSH端口号。
4 软件镜像源
在/etc/apt/source.list
中编辑镜像源。先使用http源 (将源中的https替换为http) 安装以下软件:
|
|
之后再使用https源。
4.1 Debian(bullseye)
参考Debian 全球镜像站, 选择相应镜像源, 比如:
#默认注释了源码镜像以提高 apt update 速度, 如有需要可自行取消注释
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
不太推荐使用官方源:
#默认注释了源码镜像以提高 apt update 速度, 如有需要可自行取消注释
deb https://deb.debian.org/debian bullseye main contrib non-free
#deb-src https://deb.debian.org/debian bullseye main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
#deb-src https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb https://deb.debian.org/debian bullseye-updates main contrib non-free
#deb-src https://deb.debian.org/debian bullseye-updates main contrib non-free
deb https://deb.debian.org/debian bullseye-backports main contrib non-free
#deb-src https://deb.debian.org/debian bullseye-backports main contrib non-free
4.2 Ubuntu(20.04 LTS)
参考Official Archive Mirrors for Ubuntu, 选择相应镜像源, 比如:
#默认注释了源码镜像以提高 apt update 速度, 如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
#deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
5 网卡驱动
5.1 Intel AX210
检测已安装的驱动: lspci -v
。高版本的Linux内核已经自带了iwlwifi-ty-a0-gf-a0-59.ucode
。
安装:
|
|
5.2 RTL8821CE
检测已安装的驱动: lspci -v
。
由于Linux内核 (kernel >= 5.9) 自带的rtw88对RTL8821CE兼容性极差, 驱动很快就会掉, 基本无法使用, 所以需要手动安装RTL8821CE无线网卡驱动。
电脑插入网线, 或者手机USB网络共享。
编辑
/etc/modprobe.d/blacklist.conf
, 添加:1
blacklist rtw88_8821ce
这样就禁用了内核自带的rtw88驱动。
从tomaspinho的GitHub仓库下载驱动。
执行命令:
1 2
sudo apt install bc module-assistant build-essential dkms sudo m-a prepare
cd
到下载的驱动的目录, 执行以下命令:1
sudo ./dkms-install.sh
默认情况下, Linux可能会启用PCIe活动状态电源管理。这可能与该驱动程序冲突。编辑
/etc/default/grub
, 在GRUB_CMDLINE_LINUX_DEFAULT
后添加pci=noaer
, 比如:1
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=noaer"
然后更新grub:
1
sudo update-grub
开机自检遇到某些报错时, 也可以在
GRUB_CMDLINE_LINUX_DEFAULT
后添加pci=noaer
来解决, 这是一个在Stack Overflow常见的解决方案。重启设备。
6 应用
6.1 常用软件
6.2 应用列表
- 首先确定待执行文件是否有可执行权限。
- 在任意位置右键新建一个
链接到应用程序
, 然后在应用程序标签下的命令里填入软件所在路径。 - 有的软件因为权限问题打不开软件, 可在路径后加上
--no-sandbox
。 - 之后将这个配置好的
.desktop
文件移动到~/.local/share/applications/
即可。
6.3 应用图标
在/usr/share/applications/
中, 编辑要更改的软件的.desktop
文件, 在Icon=
后填入自定义的软件图标路径即可。
/usr/share/pixmaps/
文件夹下 (第三方图标都默认存放在这里) , 然后在Icon=
后接图片名称即可, 不用加文件后缀, 比如现在有文件/usr/share/pixmaps/PicGo.png
, 在软件的.desktop
文件写入Icon=PicGo
即可。7 字体
提前在Windows中将需要的字体从
C:/Windows/Fonts
中复制出来, 放到C:/Users/UserName/Fonts
中。使用文件管理器(比如Dolphin)挂载Windows系统盘, 这时Windows系统盘根路径一般为
/run/media/UserName/Windows/
。在Linux中为Windows字体新建一个目录:
1
sudo mkdir /usr/share/fonts/custom
然后将Windows的字体文件复制过来:
1 2
sudo cp /run/media/UserName/Windows/Users/UserName/Fonts/* /usr/share/fonts/custom sudo cp /run/media/UserName/Windows/Users/UserName/Fonts/* /usr/share/fonts/custom