环境部署
查看发行版版本
Apt 换源
1
2
| sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
|
Zerotier 安装
虚拟局域网,方便跨局域网间的 SSH 连接。
1
2
3
4
5
| curl -s https://install.zerotier.com | sudo bash
sudo zerotier-cli join <YOUR_NETWORK_ID>
sudo systemctl enable --now zerotier-one
systemctl status zerotier-one
|
启用 mDNS
使得局域网内可以使用 {hostname}.local 访问到主机。
1
2
3
| sudo apt install avahi-daemon -y
sudo systemctl start --now avahi-daemon
systemctl status avahi-daemon # 查看 avahi-daemon 启动状态
|
(可选:修改主机名)
1
| sudo hostnamectl set-hostname <NEW_HOSTNAME>
|
创建新sudo用户
方法一(推荐)
1
2
| sudo adduser username
sudo usermod -aG sudo username
|
方法二
1
2
3
4
| sudo useradd -m username # -m 选项会自动创建 /home/username 目录
sudo passwd username
sudo useradd -m -s /bin/bash username # -s /bin/bash 让用户使用 bash 作为默认 shell
sudo useradd -m -g users -G sudo username # -g users 设定主组, -G sudo 让用户加入 sudo 组(赋予 sudo 权限)
|
相关命令总结
任务 | 命令 |
---|
创建用户(无家目录) | sudo useradd username |
创建用户并创建家目录 | sudo useradd -m username |
交互式创建用户 | sudo adduser username |
设置密码 | sudo passwd username |
赋予 sudo 权限 | sudo usermod -aG sudo username |
删除用户 | sudo userdel username |
删除用户并删除家目录 | sudo userdel -r username |
Oh-my-zsh 安装
首先安装 zsh
1
| sudo apt install zsh -y
|
然后安装 oh-my-zsh
1
| sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
插件下载和使用
1
2
3
4
5
6
| git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
vim ~/.zshrc
source ~/.zshrc
|
1
2
3
| # 添加到 ~/.zshrc
plugins=(git web-search jsontools z zsh-syntax-highlighting zsh-autosuggestions)
export ZSH_AUTOSUGGEST_STRATEGY=(history completion)
|
1
| docker pull forceless/pptagent
|
安装 Powerlevel10k 主题
1
| git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
|
配置 SSH 秘钥
只有公钥可以上传,服务器使用公钥来验证由私钥生成的签名,认证客户端身份。
客户端生成公钥
1
| ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
将公钥上传到服务器
1
2
3
4
5
6
7
8
9
| # Windows 客户端
scp ~/.ssh/id_rsa.pub user@example.com:~/
# 在服务器端执行下面的命令
mkdir ~/.ssh
chmod 700 ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm ~/id_rsa.pub
|
1
2
| # Linux 客户端
ssh-copy-id user@example.com
|
软件安装
Docker 安装
1
2
| curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.shdocker pull forceless/pptagent
|
(可选)添加用户到 docker 组
1
2
| sudo usermod -aG docker <username>
newgrp docker
|
Clang 套件安装
1
2
3
4
5
6
7
8
9
10
11
12
13
| # 1. clangd
sudo apt install clangd
# xx替换为填写安装的clangd版本号
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-xx 100
# 2. clang-tidy
sudo apt install clang-tidy
# 3. clang-format
sudo apt install clang-format
# 4. clang
sudo apt install clang
|
.clang-format 配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| BasedOnStyle: WebKit
Language: Cpp
# 缩进规则
UseTab: Never # 禁止使用真实 Tab 字符,改用空格模拟
TabWidth: 4 # 1 个 Tab 对应 4 个空格
IndentWidth: 4 # 缩进宽度为 4 个空格(等同于 Tab 宽度)
# 大括号换行风格(与 WebKit 风格一致)
BreakBeforeBraces: Linux
# 其他常用 WebKit 风格优化
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
BinPackParameters: false # 禁止将函数参数挤在一行
ColumnLimit: 120 # 行宽限制 120
PointerAlignment: Right # 指针符号 `*` 靠近类型名
SpaceBeforeParens: ControlStatements # `if`/`for` 等控制语句后加空格
# 额外自定义规则(可选)
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: true
AlignConsecutiveDeclarations: false # 变量对齐
|