Files
sshworkshop/setups/linux.sh
2025-11-04 21:10:31 +01:00

18 lines
850 B
Bash
Executable File

#!/bin/bash
dpkg-reconfigure openssh-server
# my_username=$(shuf -n 1 /etc/workshopnames.yml | cut -b 3-)
udhcpc -i eth0 -x hostname:$(hostname) -F $(hostname)
# once we have our IP, create the matching user.
my_last_octet=$(ip -4 a s dev eth0 | grep / | cut -f 4 -d . | cut -f 1 -d /)
my_username_pwhash=$(sed -n "${my_last_octet}{p;q}" /etc/workshopnames.yml)
my_username="${my_username_pwhash%%:*}"
my_pwhash_pwd="${my_username_pwhash#*: }"
my_pwhash=${my_pwhash_pwd%%,*}
my_pwd=${my_pwhash_pwd#*,}
useradd -m ${my_username} -p "${my_pwhash}" -s /bin/bash
su - ${my_username} -c 'mkdir .ssh'
echo "$my_pwd" > /home/${my_username}/PASSWORD
# cp /root/.ssh/authorized_keys /home/${my_username}/.ssh/ && chown ${my_username}:${my_username} /home/${my_username}/.ssh/authorized_keys
printf "172.16.202.33\tjumphost1\n" >> /etc/hosts
/usr/sbin/sshd -D