Skip to content

Commit

Permalink
feat(cac): add script to configure alpine linux vm image for vedv
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed May 9, 2023
1 parent 3f5a93c commit 6ef371b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cac/configure-image.alpine-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env sh

set -eu

readonly DEFAULT_USER="${DEFAULT_USER:-vedv}"
readonly DEFAULT_PASS="${DEFAULT_PASS:-vedv}"

# add user
adduser --disabled-password "$DEFAULT_USER"
echo "${DEFAULT_USER}:${DEFAULT_PASS}" | chpasswd

# change root password
echo "root:${DEFAULT_PASS}" | chpasswd

# enable community repository
readonly COMMUNITY_REPO="$(grep 'alpine/v.*/community' /etc/apk/repositories | sed 's/\//\\\//g')"
readonly ENABLED_COMMUNITY_REPO="$(echo "$COMMUNITY_REPO/" | sed 's/^#//')"
sed -i "s/${COMMUNITY_REPO}/${ENABLED_COMMUNITY_REPO}" /etc/apk/repositories

# install sudo
apk add sudo
# configure sudoers
adduser "$DEFAULT_USER" wheel
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/"${DEFAULT_USER}-nopasswd"

# install openssh
apk add openssh
# configure sshd
sed -i \
-e 's/^#\?\s*PermitRootLogin .*/PermitRootLogin yes/' \
-e 's/^#\?\s*PasswordAuthentication .*/PasswordAuthentication yes/' \
/etc/ssh/sshd_config

service sshd restart

0 comments on commit 6ef371b

Please sign in to comment.