File size: 2,652 Bytes
81f5c26
 
 
 
 
 
 
 
 
 
 
 
 
8d515de
81f5c26
 
 
 
 
 
8d515de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3379918
 
 
8d515de
3379918
 
8d515de
 
 
 
 
 
 
81f5c26
bbe7450
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

# 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 keep the container running
keep_container_running() {
    tail -f /var/log/auth.log
}

generate_admin_ssh_keys() {
    if [ ! -f /home/admin/.ssh/id_rsa ]; then
        echo "* Generating SSH keys for 'admin' user *"
        mkdir -p /home/admin/.ssh || { echo "Failed to create .ssh directory"; exit 1; }
        #ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N "" 
        #yes y | ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -N "" || { echo "Failed to generate admin SSH key"; exit 1; }
        yes y | ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -N "" || { echo "Failed to generate admin SSH key"; exit 1; }
        ssh-keyscan -p 2222 127.0.0.1 >> /home/admin/.ssh/known_hosts
        cp /home/admin/.ssh/known_hosts /home/admin/.ssh/ssh_known_hosts
        #ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 admin@localhost
        chown -R admin:admin /home/admin
        #chmod -R 777 /home/admin/.ssh
        chmod 700 /home/admin/.ssh || { echo "Failed to set .ssh directory permissions"; exit 1; }
        chmod 600 /home/admin/.ssh/id_rsa || { echo "Failed to set private key permissions"; exit 1; }
        chmod 644 /home/admin/.ssh/id_rsa.pub || { echo "Failed to set public key permissions"; exit 1; }
    fi
}
add_admin_authorized_keys() {    
  #echo "* Adding public key to authorized_keys for 'admin' user *"
  #echo "* Admin Public Key :$(cat /home/admin/.ssh/id_rsa.pub)"
  #echo "* Admin Private Key :$(cat /home/admin/.ssh/id_rsa.pub)"
  cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys || { echo "Failed to add public key to authorized_keys"; exit 1; }
  #echo "* Authorised Keys: $(cat /home/admin/.ssh/authorized_keys)"
  #echo "* Known HOST File :$(cat /home/admin/.ssh/known_hosts)"
  #chmod 600 /home/admin/.ssh/authorized_keys || { echo "Failed to set authorized_keys permissions"; exit 1; } 
}
echo "password" || su - admin
echo "I am : $(whoami)"
generate_admin_ssh_keys
add_admin_authorized_keys
tail -f /var/log/auth.log

echo "* Activating virtual environment *"
source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
echo "* Starting WebSSH application *PWD $(pwd)*"
cd /app || { echo "Failed to change directory to /app"; exit 1; }
python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; }