1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UbuntuLXCに色々建てるshellscript達

Last updated at Posted at 2025-12-16

備忘録がてらAIが出したコードでちゃんと動くやつをおいておく。

目次

1.Code-server
2.Authentik

環境

  • Ubuntu(LXC)

動かし方

nano a.sh

コピペして保存。

chmod 777 a.sh

パーミッションを雑に設定

./a.sh

実行。

Code-server

以下のshellscriptをコピペしてください。

既定の設定

  • 実行ユーザー:coder
  • 認証:password
  • ポート:8080
    変更するときはshファイルの先頭にある設定をいじってください。
#!/bin/bash
set -e

# ===== 設定 =====
USERNAME="coder"
PASSWORD="password"
CODE_SERVER_PORT=8080
# ===== 設定終わり =====
if ! id "$USERNAME" >/dev/null 2>&1; then
    useradd -m -s /bin/bash "$USERNAME"
    echo "${USERNAME}:${PASSWORD}" | chpasswd
fi

usermod -aG sudo "$USERNAME"

apt update
apt install -y curl sudo systemd git

curl -fsSL https://code-server.dev/install.sh | sh

CONFIG_DIR="/home/${USERNAME}/.config/code-server"
mkdir -p "$CONFIG_DIR"
chown -R ${USERNAME}:${USERNAME} "/home/${USERNAME}/.config"

cat <<EOF > "${CONFIG_DIR}/config.yaml"
bind-addr: 0.0.0.0:${CODE_SERVER_PORT}
auth: password
password: ${PASSWORD}
cert: false
EOF

chown ${USERNAME}:${USERNAME} "${CONFIG_DIR}/config.yaml"
chmod 600 "${CONFIG_DIR}/config.yaml"

systemctl enable --now code-server@${USERNAME}

echo "=================================="
echo "code-server is running!"
echo "User      : ${USERNAME}"
echo "Password  : ${PASSWORD}"
echo "Port      : ${CODE_SERVER_PORT}"
echo "=================================="

アクセス

http://<LXCのIP>:8080

Authentik

以下のshellscriptをコピペしてください。

#!/bin/sh
set -eu

### ===== 設定 =====
BASE_DIR="/opt/authentik"
COMPOSE_URL="https://docs.goauthentik.io/docker-compose.yml"
TIMEZONE="Asia/Tokyo"
### =================

echo "[1/6] 必要パッケージのインストール"
apt update
apt install -y \
  ca-certificates \
  curl \
  gnupg \
  lsb-release \
  docker.io \
  docker-compose

systemctl enable --now docker

echo "[2/6] 作業ディレクトリ作成"
mkdir -p "$BASE_DIR"
cd "$BASE_DIR"

echo "[3/6] docker-compose.yml 取得"
curl -fsSL "$COMPOSE_URL" -o docker-compose.yml

echo "[4/6] 環境変数ファイル作成"
if [ ! -f .env ]; then
  cat > .env <<EOF
AUTHENTIK_SECRET_KEY=$(openssl rand -base64 50)
AUTHENTIK_ERROR_REPORTING__ENABLED=false
AUTHENTIK_POSTGRESQL__PASSWORD=$(openssl rand -base64 36)
PG_PASS=\${AUTHENTIK_POSTGRESQL__PASSWORD}
TZ=${TIMEZONE}
EOF
fi

echo "[5/6] Docker コンテナ起動"
docker-compose pull
docker-compose up -d

echo "[6/6] 起動確認"
docker ps --format "table {{.Names}}\t{{.Status}}"

アクセス

初期設定URL

http://<LXCのIP>:9000/if/flow/initial-setup/

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?