#/bin/sh if [ "$EUID" -ne 0 ] then echo "Please run as root" exit 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 mkdir /home/akanealw/.ssh chown akanealw:akanealw /home/akanealw/.ssh chmod 700 /home/akanealw/.ssh cp /root/.ssh/authorized_keys /home/akanealw/.ssh > /dev/null 2>&1 chown akanealw:akanealw /home/akanealw/.ssh/authorized_keys > /dev/null 2>&1 chmod 600 /home/akanealw/.ssh/authorized_keys > /dev/null 2>&1 fi # create akanealw file in /etc/sudoers.d if [[ ! -f /etc/sudoers.d/akanealw ]] then echo "akanealw ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/akanealw fi usermod -a -G sudo akanealw # authorized_keys akanealw 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") if [ $isInFile -eq 0 ] then echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBKYj+eRQsvdLvrJNoqugb9A7iQT+BEPb6LI9BseyhWR winpc-akanealw" >> /home/akanealw/.ssh/authorized_keys chown akanealw:akanealw /home/akanealw/.ssh/* chmod 600 /home/akanealw/.ssh/* 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 chown akanealw:akanealw /home/akanealw/.ssh/* chmod 600 /home/akanealw/.ssh/* fi # config /home/akanealw/.ssh/ isInFile=$(cat /home/akanealw/.ssh/config | grep -c "*-root") if [ $isInFile -eq 0 ] then cp /home/akanealw/.ssh/config /home/akanealw/.ssh/config.bak > /dev/null 2>&1 mv /home/akanealw/.ssh/known_hosts /home/akanealw/.ssh/known_hosts.old > /dev/null 2>&1 echo "" >> /home/akanealw/.ssh/config echo "" >> /home/akanealw/.ssh/config echo "Host *-root" >> /home/akanealw/.ssh/config echo "User root" >> /home/akanealw/.ssh/config echo "IdentityFile /root/.ssh/server-root" >> /home/akanealw/.ssh/config echo "" >> /home/akanealw/.ssh/config echo "Host *" >> /home/akanealw/.ssh/config echo "Port 22" >> /home/akanealw/.ssh/config echo "User akanealw" >> /home/akanealw/.ssh/config echo "IdentityFile /home/akanealw/.ssh/server-akanealw" >> /home/akanealw/.ssh/config chown akanealw:akanealw /home/akanealw/.ssh/* chmod 600 /home/akanealw/.ssh/* fi # server-akanealw if [[ ! -f /home/akanealw/.ssh/server-akanealw ]] then echo "-----BEGIN OPENSSH PRIVATE KEY-----" > /home/akanealw/.ssh/server-akanealw echo "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW" >> /home/akanealw/.ssh/server-akanealw echo "QyNTUxOQAAACBgIsNLEMcU4P8wZvx8+Cy47Yrhn3nxdr6IBpGHFqMeEgAAAJgPgcu8D4HL" >> /home/akanealw/.ssh/server-akanealw echo "vAAAAAtzc2gtZWQyNTUxOQAAACBgIsNLEMcU4P8wZvx8+Cy47Yrhn3nxdr6IBpGHFqMeEg" >> /home/akanealw/.ssh/server-akanealw echo "AAAEDalS9Q+0KRMMqOXnie/d0uckbLIePYYY7DOqs8cJ7UF2Aiw0sQxxTg/zBm/Hz4LLjt" >> /home/akanealw/.ssh/server-akanealw echo "iuGfefF2vogGkYcWox4SAAAAD3NlcnZlci1ha2FuZWFsdwECAwQFBg==" >> /home/akanealw/.ssh/server-akanealw echo "-----END OPENSSH PRIVATE KEY-----" >> /home/akanealw/.ssh/server-akanealw chown akanealw:akanealw /home/akanealw/.ssh/* chmod 600 /home/akanealw/.ssh/* fi # restart sshd systemctl restart ssh systemctl restart sshd