添加 SSH 密钥对生成和配置

This commit is contained in:
2025-05-01 10:29:34 +08:00
parent b630ca1eaa
commit e76d426a38

24
main.tf
View File

@@ -50,6 +50,30 @@ resource "coder_agent" "main" {
# Prepare user home with default files on first start.
if [ ! -f ~/.init_done ]; then
cp -rT /etc/skel ~
# 创建 .ssh 目录并设置权限
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# 生成 SSH 密钥对,不设置密码
ssh-keygen -t ed25519 -f ~/.ssh/git -N "" -C "${data.coder_workspace_owner.me.email}"
# 创建 SSH 配置文件
cat > ~/.ssh/config <<EOF
Host ssh.lionhao.top
Port 4022
User git
IdentityFile ~/.ssh/git
EOF
# 设置适当的权限
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/git
chmod 644 ~/.ssh/git.pub
echo "SSH key pair created. Your public key is:"
cat ~/.ssh/git.pub
touch ~/.init_done
fi