Spaces:
Paused
Paused
| # Function to print the current hostname and user details | |
| print_host_details() { | |
| #echo "0.0.0.0 abc" | sudo tee -a /etc/hosts | |
| echo "* The hostname of this container is: $(cat /etc/hostname). PWD $(pwd)" | |
| echo "* The host File of this container is: $(cat /etc/hosts)" | |
| echo "* The Sudoers of this container is: $(cat /etc/sudoers)" | |
| echo "* ID of the user running the script:$(whoami) *ID : $(id -u) * Group: $(id -g)" | |
| #echo "* Changing User to Admin :$(echo "toor" || su - admin)" | |
| echo "* Current User WHO AM I $(whoami)" | |
| echo "* Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')" | |
| } | |
| # Function to generate SSH host keys if missing | |
| generate_ssh_keys() { | |
| rm -rf /etc/ssh/ssh_host_rsa_* | |
| rm -rf /etc/ssh/ssh_host_ecdsa_* | |
| rm -rf /etc/ssh/ssh_host_ed25519_* | |
| rm -rf /etc/ssh/ssh_known_* | |
| echo "* Generating SSH host keys *" | |
| yes y | ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; } | |
| yes y | ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; } | |
| yes y | ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; } | |
| ssh-keyscan -p 2222 127.0.0.1 >> /etc/ssh/ssh_known_hosts | |
| cp /etc/ssh/ssh_known_hosts /etc/ssh/known_host | |
| #ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" | |
| #ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" | |
| #ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" | |
| echo " Public Key:" | |
| cat /etc/ssh/ssh_host_rsa_key.pub | |
| echo " Private Key :" | |
| cat /etc/ssh/ssh_host_rsa_key | |
| echo " Host Files :" | |
| cat /etc/ssh/ssh_known_host | |
| } | |
| # Function to start SSH service if not running | |
| start_ssh_service() { | |
| if ! pgrep -x "sshd" >/dev/null; then | |
| echo "* Starting SSH server at port 2222 *" | |
| /usr/sbin/sshd -p 2222 || { echo "Failed to start SSH server"; exit 1; } | |
| #/usr/sbin/sshd -D -e -ddd|| { echo "Failed to start SSH server"; exit 1; } | |
| else | |
| echo "* SSH server is already running *" | |
| fi | |
| } | |
| # Function to activate virtual environment | |
| activate_virtual_env() { | |
| if [ -d "/app/WebSSHEnv" ]; then | |
| echo "* Activating virtual environment *" | |
| source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; } | |
| else | |
| echo "* Virtual environment not found, please check setup *" | |
| fi | |
| } | |
| # Function to set working directory | |
| set_working_directory() { | |
| cd /app || { echo "Failed to change directory to /app"; exit 1; } | |
| } | |
| # Function to print the contents of the working directory | |
| print_working_directory_contents() { | |
| echo "* Contents of /app directory: *" | |
| ls -la /app | |
| } | |
| # Function to run the WebSSH application | |
| run_webssh_application() { | |
| echo "* Starting WebSSH application *" | |
| python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; } | |
| } | |
| # Function to keep the container running | |
| keep_container_running() { | |
| tail -f /var/log/auth.log | |
| } | |
| # Main script execution | |
| print_host_details | |
| generate_ssh_keys | |
| start_ssh_service | |
| #sshd -T | grep -i 'known hosts' | |
| echo "* Status of SSH service: *" | |
| netstat -tuln | |
| echo "* Testing admin's SSH login locally *" | |
| echo "password" | ssh -v -o /etc/ssh/ssh_host_rsa_key.pub admin@localhost -p 2222 | |
| activate_virtual_env | |
| set_working_directory | |
| print_working_directory_contents | |
| run_webssh_application | |
| keep_container_running |