lxc patch 12
This commit is contained in:
@@ -17,7 +17,7 @@ lxc-create -n "$CONTAINER" -f /etc/lxc/default.conf -t download -- -d ubuntu -r
|
||||
|
||||
# write resolv.conf into rootfs before boot
|
||||
mkdir -p "/var/lib/lxc/${CONTAINER}/rootfs/etc"
|
||||
rm -f "/var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf" # remove if symlink
|
||||
rm -f "/var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf"
|
||||
echo "nameserver 8.8.8.8" > "/var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf"
|
||||
|
||||
# assign static IP via LXC config (host-side, always works)
|
||||
@@ -27,9 +27,6 @@ lxc.net.0.ipv4.gateway = 10.100.0.1
|
||||
lxc.start.auto = 1
|
||||
EOF
|
||||
|
||||
# write resolv.conf into rootfs before boot
|
||||
# echo "nameserver 8.8.8.8" > "/var/lib/lxc/${CONTAINER}/rootfs/etc/resolv.conf"
|
||||
|
||||
# disable any in-container networking that might fight us
|
||||
rm -f "/var/lib/lxc/${CONTAINER}/rootfs/etc/netplan/"*.yaml 2>/dev/null || true
|
||||
mkdir -p "/var/lib/lxc/${CONTAINER}/rootfs/etc/netplan"
|
||||
@@ -46,10 +43,20 @@ EOF
|
||||
lxc-start -n "$CONTAINER"
|
||||
sleep 5
|
||||
|
||||
# install SSH, inject key
|
||||
# install SSH + VSCode Remote prerequisites
|
||||
lxc-attach --clear-env -n "$CONTAINER" -- /bin/bash -c "
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
apt-get update && apt-get install -y openssh-server
|
||||
apt-get update && apt-get install -y \
|
||||
openssh-server \
|
||||
curl wget ca-certificates \
|
||||
git \
|
||||
tar gzip \
|
||||
procps \
|
||||
locales
|
||||
# generate a UTF-8 locale (VSCode expects this)
|
||||
sed -i 's/# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
|
||||
locale-gen
|
||||
# SSH config
|
||||
mkdir -p /root/.ssh
|
||||
chmod 700 /root/.ssh
|
||||
sed -i 's/#PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
|
||||
@@ -64,8 +71,6 @@ cat "$KEYFILE" | lxc-attach --clear-env -n "$CONTAINER" -- /bin/bash -c "
|
||||
"
|
||||
|
||||
# create host user
|
||||
# useradd -m -s /bin/bash -G labmates "$USER" 2>/dev/null || true
|
||||
# useradd -m -s /bin/bash -G labmates -U "$USER" 2>/dev/null || true
|
||||
useradd -m -s /run/current-system/sw/bin/bash -G labmates -U "$USER" 2>/dev/null || true
|
||||
mkdir -p "/home/${USER}/.ssh"
|
||||
cp "$KEYFILE" "/home/${USER}/.ssh/authorized_keys"
|
||||
|
||||
Reference in New Issue
Block a user