Spaces:
Paused
Paused
BinaryONe
commited on
Commit
·
888a566
1
Parent(s):
8d515de
Changes
Browse files
init.sh
CHANGED
|
@@ -1,69 +1,57 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
echo "* Hi There I am Booting up : $(whoami)"
|
| 3 |
# Function to print the current hostname and user details
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
# Function to generate SSH host keys if missing
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
else
|
| 47 |
-
echo "* Virtual environment not found, please check setup *"
|
| 48 |
-
fi
|
| 49 |
-
}
|
| 50 |
# Function to start SSH service if not running
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
echo "* SSH server is already running *"
|
| 62 |
-
fi
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
print_host_details
|
| 66 |
-
generate_ssh_keys
|
| 67 |
-
start_ssh_service_with_status
|
| 68 |
-
activate_python_and_run
|
| 69 |
/app/start.sh
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
echo "* Hi There I am Booting up : $(whoami)"
|
| 3 |
# Function to print the current hostname and user details
|
| 4 |
+
|
| 5 |
+
#echo "0.0.0.0 abc" | sudo tee -a /etc/hosts
|
| 6 |
+
echo "* The hostname of this container is: $(cat /etc/hostname). PWD $(pwd)"
|
| 7 |
+
echo "* The host File of this container is: $(cat /etc/hosts)"
|
| 8 |
+
echo "* The Sudoers of this container is: $(sudo cat /etc/sudoers)"
|
| 9 |
+
echo "* ID of the user running the script: $(whoami) *ID : $(id -u) * Group: $(id -g)"
|
| 10 |
+
echo "* Changing User to Admin :$(echo "password" || su - admin)"
|
| 11 |
+
echo "* Current User WHO AM I $(whoami)"
|
| 12 |
+
echo "* Status of Admin : $(id admin 2>/dev/null || echo 'Admin user not found')"
|
| 13 |
+
|
| 14 |
# Function to generate SSH host keys if missing
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
sudo rm -rf /etc/ssh/ssh_host_rsa_*
|
| 18 |
+
sudo rm -rf /etc/ssh/ssh_host_ecdsa_*
|
| 19 |
+
sudo rm -rf /etc/ssh/ssh_host_ed25519_*
|
| 20 |
+
sudo rm -rf /etc/ssh/ssh_known_*
|
| 21 |
+
|
| 22 |
+
echo "* Generating SSH host keys *"
|
| 23 |
+
yes y | ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; }
|
| 24 |
+
yes y | ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; }
|
| 25 |
+
yes y | ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; }
|
| 26 |
+
ssh-keyscan -p 2222 127.0.0.1 >> /etc/ssh/ssh_known_hosts
|
| 27 |
+
cp /etc/ssh/ssh_known_hosts /etc/ssh/known_host
|
| 28 |
+
#ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ""
|
| 29 |
+
#ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N ""
|
| 30 |
+
#ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
|
| 31 |
+
echo "* Public Key:"
|
| 32 |
+
cat /etc/ssh/ssh_host_rsa_key.pub
|
| 33 |
+
echo "* Private Key :"
|
| 34 |
+
cat /etc/ssh/ssh_host_rsa_key
|
| 35 |
+
echo "* Host Files :"
|
| 36 |
+
cat /etc/ssh/ssh_known_host
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
echo "* Activating virtual environment *"
|
| 41 |
+
source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
|
| 42 |
+
echo "* Starting WebSSH application *"
|
| 43 |
+
python3 -u -m /app/WebSSH || { echo "Failed to start WebSSH application"; exit 1; }
|
| 44 |
+
|
| 45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Function to start SSH service if not running
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
#service ssh restart
|
| 50 |
+
#service sshd restart
|
| 51 |
+
echo "* Starting SSH server at port 2222 *"
|
| 52 |
+
/usr/sbin/sshd -p 2222 || { echo "Failed to start SSH server"; exit 1; }
|
| 53 |
+
#/usr/sbin/sshd -D -e -ddd|| { echo "Failed to start SSH server"; exit 1; }
|
| 54 |
+
echo "* Status of SSH service: *"
|
| 55 |
+
netstat -tuln
|
| 56 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
/app/start.sh
|