75 lines
2.5 KiB
Bash
Executable File
75 lines
2.5 KiB
Bash
Executable File
#!/bin/ash
|
|
|
|
if [[ ! $(id -u) = 0 ]]; then
|
|
echo "Please run as root!"
|
|
exit 1
|
|
fi
|
|
|
|
# edit repositories
|
|
echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main" > /etc/apk/repositories
|
|
echo "http://dl-cdn.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories
|
|
|
|
# apk update and install essentials
|
|
apk update && apk upgrade
|
|
apk add nano sudo pwgen curl wget qemu-guest-agent git bash-doc bash-completion openssh --no-cache
|
|
|
|
# change default shell to bash
|
|
isInFile=$(cat /etc/passwd | grep -c "/bin/bash")
|
|
if [ $isInFile -eq 0 ]
|
|
then
|
|
sed -i 's/ash/bash/g' /etc/passwd
|
|
fi
|
|
|
|
# add akanealw user if not existing
|
|
isInFile=$(cat /etc/passwd | grep -c "akanealw")
|
|
if [ $isInFile -eq 0 ]
|
|
then
|
|
echo "Set password for akanealw"
|
|
useradd -m -p '$y$j9T$NB7zOwLzhMgtxiCGjzwvf.$YGAIpv6m/DIlgNT5IU5H.K.QSNMCG5/TKY9sYlfGsGB' -s /bin/bash -d /home/akanealw akanealw
|
|
fi
|
|
|
|
# add akanealw to sudo users
|
|
if [[ ! -f /etc/sudoers.d/akanealw ]]
|
|
then
|
|
echo "akanealw ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/akanealw
|
|
fi
|
|
|
|
# edit issue file
|
|
isInFile=$(cat /etc/issue | grep -c "192.168.1")
|
|
if [ $isInFile -eq 0 ]
|
|
then
|
|
ip address show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 >> /etc/issue
|
|
echo "" >> /etc/issue
|
|
fi
|
|
|
|
# remove all motd
|
|
rm /etc/motd > /dev/null 2>&1
|
|
|
|
# enable and start sshd
|
|
if [[ ! -d /etc/ssh ]]; then
|
|
rc-update add sshd
|
|
rc-service sshd start
|
|
fi
|
|
|
|
# add ssh keys for akanealw
|
|
if [[ -d /home/akanealw ]]; then
|
|
mkdir /home/akanealw/.ssh > /dev/null 2>&1
|
|
cp /home/akanealw/.ssh/authorized_keys /home/akanealw/.ssh/authorized_keys.bak > /dev/null 2>&1
|
|
isInFile=$(cat /home/akanealw/.ssh/authorized_keys | grep -c "winpc-akanealw") > /dev/null 2>&1
|
|
if [ $isInFile -eq 0 ]; then
|
|
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBKYj+eRQsvdLvrJNoqugb9A7iQT+BEPb6LI9BseyhWR winpc-akanealw" >> /home/akanealw/.ssh/authorized_keys
|
|
fi
|
|
|
|
isInFile=$(cat /home/akanealw/.ssh/authorized_keys | grep -c "server-akanealw")
|
|
if [ $isInFile -eq 0 ]; then
|
|
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGAiw0sQxxTg/zBm/Hz4LLjtiuGfefF2vogGkYcWox4S server-akanealw" >> /home/akanealw/.ssh/authorized_keys
|
|
fi
|
|
chown akanealw:akanealw /home/akanealw/.ssh/
|
|
chown akanealw:akanealw /home/akanealw/.ssh/*
|
|
chmod 600 /home/akanealw/.ssh/*
|
|
fi
|
|
|
|
# disable ssh password login
|
|
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
|
|
sed -i "/#PasswordAuthentication yes/c\PasswordAuthentication no" /etc/ssh/sshd_config
|