Change replacement method + remove useless stuff
This commit is contained in:
@@ -1,17 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
NO_FORMAT="\e[0m"
|
NF="\e[0m"
|
||||||
F_BOLD="\e[1m"
|
CR="\e[38;5;9m"
|
||||||
C_GREEN="\e[38;5;40m"
|
|
||||||
C_RED="\e[38;5;9m"
|
|
||||||
C_YELLOW="\033[38;5;226m"
|
|
||||||
USER=$(getent passwd 1000 | cut -d: -f1)
|
USER=$(getent passwd 1000 | cut -d: -f1)
|
||||||
|
|
||||||
echo -e "${C_YELLOW}WARNING: Script is meant to be run in an automated manner. Avoid running in terminal.${NO_FORMAT}"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
#Verify if root
|
#Verify if root
|
||||||
if [ "$UID" -ne 0 ]; then
|
if [ "$UID" -ne 0 ]; then
|
||||||
echo -e "${C_RED}This script must be run as root.${NO_FORMAT}"
|
echo -e "${CR}This script must be run as root.${NF}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
##Generate keys
|
##Generate keys
|
||||||
@@ -19,22 +13,26 @@ mkdir /.SSH/automated/.temp
|
|||||||
ssh-keygen -f /.SSH/automated/.temp/id_ed25519 -N "" &&
|
ssh-keygen -f /.SSH/automated/.temp/id_ed25519 -N "" &&
|
||||||
rm /.SSH/automated/priv/servers/id_ed25519
|
rm /.SSH/automated/priv/servers/id_ed25519
|
||||||
rm /.SSH/automated/pub/servers/id_ed25519.pub
|
rm /.SSH/automated/pub/servers/id_ed25519.pub
|
||||||
cp /.SSH/automated/.temp/id_ed25519 /.SSH/automated/priv/servers/
|
/.SSH/automated/.temp/id_ed25519 > /.SSH/automated/priv/servers/
|
||||||
cp /.SSH/automated/.temp/id_ed25519.pub /.SSH/automated/pub/servers/
|
/.SSH/automated/.temp/id_ed25519.pub > /.SSH/automated/pub/servers/
|
||||||
sha256sum /.SSH/automated/.temp/id_ed25519 | awk '{print $1}' | tee /home/$USER/sshprov/priv
|
sha256sum /.SSH/automated/.temp/id_ed25519 | awk '{print $1}' > /home/$USER/sshprov/priv
|
||||||
sha256sum /.SSH/automated/.temp/id_ed25519.pub | awk '{print $1}' | tee /home/$USER/sshprov/pub
|
sha256sum /.SSH/automated/.temp/id_ed25519.pub | awk '{print $1}' > /home/$USER/sshprov/pub
|
||||||
sleep 2
|
sleep 2
|
||||||
rm -rf /.SSH/automated/.temp/
|
rm -rf /.SSH/automated/.temp/
|
||||||
|
|
||||||
##Attribute to self & restart sshd
|
##Attribute to self & restart sshd
|
||||||
rm /home/$USER/.ssh/known_hosts
|
rm /home/$USER/.ssh/known_hosts
|
||||||
rm /root/.ssh/known_hosts
|
rm /root/.ssh/known_hosts
|
||||||
cat /.SSH/automated/priv/servers/id_ed25519 | tee /root/.ssh/id_ed25519
|
rm /root/.ssh/id_ed25519
|
||||||
cat /.SSH/automated/pub/servers/id_ed25519.pub | tee /root/.ssh/authorized_keys &&
|
rm /root/.ssh/authorized_keys
|
||||||
|
/.SSH/automated/priv/servers/id_ed25519 > /root/.ssh/id_ed25519
|
||||||
|
/.SSH/automated/pub/servers/id_ed25519.pub > /root/.ssh/authorized_keys &&
|
||||||
chmod 700 /root/.ssh/id_ed25519
|
chmod 700 /root/.ssh/id_ed25519
|
||||||
chmod 644 /root/.ssh/authorized_keys
|
chmod 644 /root/.ssh/authorized_keys
|
||||||
cat /.SSH/automated/priv/servers/id_ed25519 | tee /home/$USER/.ssh/id_ed25519
|
rm /home/$USER/.ssh/id_ed25519
|
||||||
cat /.SSH/automated/pub/servers/id_ed25519.pub | tee /home/$USER/.ssh/authorized_keys &&
|
rm /home/$USER/.ssh/authorized_keys
|
||||||
|
/.SSH/automated/priv/servers/id_ed25519 > /home/$USER/.ssh/id_ed25519
|
||||||
|
/.SSH/automated/pub/servers/id_ed25519.pub > /home/$USER/.ssh/authorized_keys &&
|
||||||
chmod 700 /home/$USER/.ssh
|
chmod 700 /home/$USER/.ssh
|
||||||
chmod 600 /home/$USER/.ssh/id_ed25519
|
chmod 600 /home/$USER/.ssh/id_ed25519
|
||||||
chmod 600 /home/$USER/.ssh/authorized_keys
|
chmod 600 /home/$USER/.ssh/authorized_keys
|
||||||
|
|||||||
Reference in New Issue
Block a user