Debian 的基本配置
开始之前
这里假设已经有了一个安装好 Debian 的云服务器。它的 IP 地址已经解析到 maze.com 域名。同时掌握了 root 密码,这样我们就可以登录服务器了。目前使用的 Debian 的版本是 12。
主机基本的设置
$ ssh root@maze.com
root@maze.com's password:首先,我们需要设置主机名为 maze.com。
$ cat /etc/hostname
maze.com新用户
通常我们不会使用 root 直接运行命令,而是创建一个能够执行 sudo 的普通用户。这里我们用 mazeuser。让 mazeuser 有 sudo 权限,将以下内容添加到 /etc/sudoers 中,这样就可以不需要密码执行 sudo 了。
# 在远程机器上,使用 root 账号
$ useradd mazeuser -m -s /bin/bash
$ /sbin/visudo
$ cat /etc/sudoers
maze ALL=(ALL) NOPASSWD: ALL创建 SSH 密钥
接下来我们创建 ssh 密钥用来无密码远程登录。在创建 SSH 密钥之前,我们需要先设置 mazeuser 的密码。
$ passwd mazeuser
New password:
Retype new password:
passwd: password updated successfully接下来我们用 ssh-keygen 在本地的机器上生成一个 ssh 密钥对。然后使用 ssh-copy-id 命令拷贝本地的 ssh 公钥到远程的机器上,这样下次登录就可以不用输入密码了。
# 在本地机器,使用当前账号
ssh-keygen # 产生一个公私钥对
ssh-copy-id -i ~/.ssh/id_ed25519.pub mazeuser@maze.com # 公钥复制到远程机器
mazeuser@maze.com's password:修改本地的 ~/.ssh/config 文件,添加如下内容:
Host maze.com
IdentityFile ~/.ssh/id_ed25519
User mazeuser现在我们用 ssh 登录到 maze.com 上。把已经有的 password 删除。
$ sudo passwd -d root
passwd: password changed.
$ sudo passwd -d maze
passwd: password changed.更新软件包
日常需要更新 Debian 的软件包
$ sudo apt update
$ sudo apt upgrade -y
$ sudo apt autoremove -y
$ sudo /sbin/reboot安装必要的软件
安装 Caddy 服务器
我们使用 Caddy 服务器来作为我们的 Web 服务器,它会自动处理 SSL 证书的申请和更新,以及 HTTP 到 HTTPS 的跳转。同时它也是我们的反向代理服务器。
$ sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
$ sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
$ sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list
$ sudo apt update
$ sudo apt install caddy启动 Caddy 服务器
$ sudo systemctl enable caddy
$ sudo systemctl start caddy安装 Node.js
由于 Debian 12 默认的 Node.js 版本比较低,我们直接通过 nvm 安装 Node.js 25 版本。
# 下载并安装 nvm:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# 代替重启 shell
$ \. "$HOME/.nvm/nvm.sh"
# 下载并安装 Node.js:
$ nvm install 25
$ nvm use 25
# 安装 pnpm
$ curl -fsSL https://get.pnpm.io/install.sh | bash
$ node -v
v25.2.1
$ npm -v
11.6.2
$ $pnpm -v
10.23.0安装 Podman
运行 Podman 需要 rootlesskit 来支持。我们可以通过下面的命令来安装 rootlesskit。
$ sudo apt install -y rootlesskit我们使用 Homebrew 来安装最新版本的 Podman。
$ brew install podman安装完成后,我们可以通过下面的命令来检查安装是否成功。
$ podman version启用 rootless 模式
$ sudo /sbin/sysctl kernel.unprivileged_userns_clone=1
$ sudo /sbin/usermod --add-subuids 100000-165535 --add-subgids 100000-165535 mazeuser现在,我们可以使用 podman 命令来运行容器了。
$ podman run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/