Linux 使用笔记
Linux 系统初使用?
说来话长了。。。本人小时候家里没有电脑,平时也基本接触不到电脑。在21年的时候,估计是贴吧逛多了,然后按捺不住,想要拥有一台自己的电脑玩些奇奇怪怪的东西,于是偷偷地省父母给的饭钱,在 keng duo duo 买了一堆硬件回来组装电脑。接着,用手机、自己拆充电线焊接的 OTG 转接器、还有内存卡做了个系统盘,装机。显示器用的还是楼下捡的 VGA 监视器……
开始只是浅浅地看些番玩些 Gal 罢了,但是后来因为沉迷了某部偶像番, 也慢慢地(大概?)接触到了字幕圈还有压制圈,认识了许多的大佬,学到了许多的知识,不过似乎还学了一些好像无关紧要的知识。不过也似乎是因为过于沉迷这些新奇的事物,而且还把这些东西当作了逃避现实世界的避风港,搞得整个高中的学业都没搞好,人际关系也是一团糟,身体素质也差了不少。
之后因为一些奇奇怪怪的缘由(已经记不清楚了,大概是建站?),开始用起了 Linux 系统。开始先是用个机顶盒刷了 Armbian,然后又去买了些竞价实例的云服务器玩玩,再后来到实体机安装,发现 Linux 系统还挺省内存的,软件也好编译和开优化,性能也比 Windows 好点(大概是因为内存不够用又不想额外花钱)。
最近这段时间先是用了 Ubuntu,但发现坑太多,于是听从大佬的建议,上了基于 ArchLinux 的 Manjaro,确实舒服不少。好了不说了,接下来就是一些从杂七杂八的地方搜罗来的笔记了。
Ubuntu 使用笔记
1 | # rpm 包转换为 deb 包以及 deb 包的安装 |
Manjaro 使用笔记
时间配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 由于我是双系统,而且不需要很精确的时间,所以才 'set-local-rtc'
# 不过应该有更好的方法?
# 安装 chrony 自动校时
sudo pacman -S chrony
sudo systemctl enable chronyd --now
sudo timedatectl set-ntp 1
sudo timedatectl set-local-rtc 1
# 同步硬件时钟
sudo hwclock --localtime --systohc
# ntp 手动校时(备选)
sudo ntpdate time.windows.com包管理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31# 配置国内镜像
# 更新时出现大量包版本回退的情况可以先检查镜像状态:https://repo.manjaro.org/
sudo pacman-mirrors -c China
# 目前 manjaro 的镜像会自己更新,如果不想它更新的话就可以这样操作
# https://forum.manjaro.org/t/should-i-update-my-mirrors/165936/
sudo systemctl disable pamac-mirrorlist.timer --now
sudo systemctl mask pamac-mirrorlist.timer
# 若需要恢复:
sudo systemctl enable pamac-mirrorlist.timer --now
# 添加 ArchLinuxCN
# https://www.archlinuxcn.org/archlinux-cn-repo-and-mirror/
# https://mirrors.ustc.edu.cn/help/archlinuxcn.html
# 在 /etc/pacman.conf 文件末尾添加两行:
[archlinuxcn]
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
# 接着执行
sudo pacman -Syyu
sudo pacman -S archlinuxcn-keyring
# 某次更新系统,不知是系统问题还是我手贱,导致 archlinux-keyring 安装出错了
# archlinux-keyring 的所有文件均为 0B,无法更新软件包,遂这样解决(建议还是先看一下 aur 以及 archlinux wiki 再操作):
sudo rm -f /usr/bin/archlinux-keyring-wkd-sync /usr/lib/systemd/system/archlinux-keyring-wkd-sync.service /usr/lib/systemd/system/archlinux-keyring-wkd-sync.timer /usr/lib/systemd/system/timers.target.wants/archlinux-keyring-wkd-sync.timer /usr/share/pacman/keyrings/archlinux-revoked /usr/share/pacman/keyrings/archlinux-trusted /usr/share/pacman/keyrings/archlinux.gpg
sudo pacman -Syy archlinux-keyring
# 重置软件包 pgp
sudo rm -rf /etc/pacman.d/gnupg
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman-key --refresh-keys字体
1
sudo pacman -S noto-fonts-cjk noto-fonts-extra
引导、启动等
1
2
3
4# 重新生成 grub 引导 (如果系统语言已经改成中文的话,引导界面也会改成中文)
sudo grub-mkconfig -o /boot/grub/grub.cfg
# 重新生成 initramfs
sudo mkinitcpio -P开启 BBR
1
2
3
4# 开启bbr
# https://forum.manjaro.org/t/how-to-enable-tcp-bbr-in-manjaro/82787/2
sudo bash -c 'echo "net.ipv4.tcp_congestion_control = bbr" > /etc/sysctl.d/50-congestion_control.conf'
sudo sysctl --system证书
1
2
3
4
5
6
7
8
9# https://wiki.archlinux.org/title/User:Grawity/Adding_a_trusted_CA_certificate
# https://www.cnblogs.com/jokershow/p/18522948
# - 添加
sudo trust anchor --store myCA.crt
sudo update-ca-trust
# - 删除
trust list | grep -i -5
sudo trust anchor --remove "pkcs11:id=xxxxxxxx"
sudo update-ca-trust上次手残,想用deb包的安装残留文件列表删除它,结果忘记里面有文件的根目录,把系统给删崩了😅
约等于执行了 rm -R /usr/lib /usr/share,
记下抢救&修复过程1
2
3
4
5
6
7
8
9
10
11
12
13
14# 用 ventoy 启动盘启动 manjaro 的 livecd
# 复制 livecd 内文件,然后重新安装所有软件包
sudo mount /dev/your_root_disk /mnt
sudo cp -rf /usr/lib/* /mnt/usr/lib/*
sudo cp -rf /usr/bin/* /mnt/usr/bin/*
manjaro-chroot -a /mnt
## 以下命令均在 chroot 中执行
pacman-mirrors -c China
pacman -Qnq | pacman -S -
## 覆盖安装,删除 livecd 残留
pacman -S --overwrite '*' manjaro-live-portable-efi manjaro-live-systemd manjaro-live-skel manjaro-live-base
pacman -R manjaro-live-portable-efi manjaro-live-systemd manjaro-live-skel manjaro-live-base
CentOS7 使用
额,本来是不想折腾这个系统的,但是这个学期换专业了,不得不折腾了 [苦笑]
镜像的话,我是下载的 Minimal 2009 版本,然后安装在了 VMWare 上,具体过程这里就省略了(
接下来的话是安装后的操作。
- 网络配置
发现安装 Minimal 后网络需要另外配置,不过也可以在安装的图形界面修改配置(具体暂时不展开
教程:https://www.cnblogs.com/huanghanyu/articles/17278061.html (还是习惯使用中文,估计英文文档的话会更详细吧)
1
2
3
4
5
6
7
8
9
10
11
12ip addr # 首先查看你的网卡
vi /etc/sysconfig/network-scripts/ifcfg-ens33
# ifcfg-ens33 指的是你可以连接外网的网卡,根据实际修改
# 修改或添加:
BOOTPROTO=dhcp
ONBOOT=yes
# vi/vim 按 i 切换输入模式,按 ESC 退出模式,接着 :wq 保存退出
# 然后:
systemctl restart network
# 到这里应该就可以使用网络相关的操作了(yum update- 网络配置
-
1
2
3
4yum -y groups install "GNOME Desktop"
startx
systemctl get-default # 查看默认使用界面
systemctl set-default graphical.target # 设置默认启动为图形界面
其他?
镜像源/软件安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18# Rust mirror
# https://mirrors.ustc.edu.cn/help/crates.io-index.html
# 在 $CARGO_HOME/config.toml 中添加如下内容 ($CARGO_HOME 在 Windows 系统默认为:%USERPROFILE%\.cargo,在类 Unix 系统默认为:$HOME/.cargo):
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"
[registries.ustc]
index = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"
# Pip mirror
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
# Install NGINX Latest Version
# see https://nginx.org/en/linux_packages.html自签名证书
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46# 用 openssl 生成自签名证书
# https://docs.openssl.org/
# (by Gemini)
# 1. 自签名证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout server.key \
-out server.pem \
-subj "/C=US/O=Org/L=China/CN=localhost"
# 2. 自签名CA证书(RSA)
## 生成CA私钥
openssl genrsa -out ca.key 2048
## 生成CA根证书 (这里的 Subject 就是 server 证书中的 Issuer)
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 \
-out ca.crt \
-subj "/C=US/O=Self Org/L=China"
## 生成服务器私钥
openssl genrsa -out server.key 2048
## 生成证书请求
## CN 可以写 localhost 或者随便一个不存在的域名
openssl req -new -key server.key -out server.csr \
-subj "/C=US/O=Self Org/L=China/CN=localhost"
# 用生成的CA证书签署这个请求
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt -days 3650 -sha256
# 3. 自签名CA证书(ECDSA)
## 创建CA
openssl ecparam -genkey -name secp384r1 -out ca.key
openssl req -x509 -new -nodes -key ca.key -sha384 -days 3650 \
-out ca.crt \
-subj "/C=US/O=Self Org/CN=Self CA"
## 生成服务器 CSR (使用配置文件,见下方)
openssl ecparam -genkey -name prime256v1 -out server.key
openssl req -new -key server.key -out server.csr -config self-ca.conf
## 用生成的CA证书签署,并带入 v3_req 扩展
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt -days 365 -sha384 \
-extfile self-ca.conf -extensions v3_reqself-ca.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28[req]
# docs: man openssl-req | https://docs.openssl.org/master/man1/openssl-req/
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
# C =
# L =
# O =
# OU =
CN = localhost
[v3_req]
# docs: man x509v3_config | https://docs.openssl.org/master/man5/x509v3_config/
keyUsage = critical, digitalSignature
extendedKeyUsage = serverAuth, clientAuth
basicConstraints = critical, CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid, issuer
authorityInfoAccess = caIssuers;URI:http://example.com/
subjectAltName = @alt_names
certificatePolicies = 2.23.140.1.2.1
crlDistributionPoints = URI:http://example.com/12345.crl
[alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1fail2ban 配置
fail2ban.local(详见fail2ban.conf)
1
2[DEFAULT]
allowipv6 = yesjail.local(详见jail.conf)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[DEFAULT]
bantime = 6mo
findtime = 10m
maxretry = 3
banaction = iptables
# SSH servers
[sshd]
filter = sshd
enabled = true
port = 22
[recidive]
enable = true
bantime = 1y
findtime = 1d
maxretry = 8
