BinaryONe commited on
Commit
19a162c
·
1 Parent(s): 1671103
Files changed (5) hide show
  1. Dockerfile +10 -7
  2. WebSSH/Dockerfile +2 -4
  3. start.sh +125 -92
  4. start_old.sh +94 -0
  5. start_upgrade.sh +0 -112
Dockerfile CHANGED
@@ -37,7 +37,9 @@ RUN useradd -m -s /bin/bash admin && \
37
  COPY . /app
38
 
39
  # Create necessary directories and set permissions
40
- RUN mkdir -p /var/run/sshd /app /app/users/ssh /app/ssh && chmod -R 777 /app /etc/sudoers
 
 
41
 
42
  # Grant full sudo access to the 'administrator' group
43
  RUN sed -i 's/Defaults !requiretty/Defaults requiretty/' /etc/sudoers && \
@@ -59,7 +61,8 @@ RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/s
59
  # Copy SSH keys to /app/ssh and set permissions
60
  RUN cp -r /etc/ssh/* /app/ssh && \
61
  chmod -R 777 /etc/ssh/* /app/ssh/* && \
62
- touch /app/ssh/ssh_known_hosts && chmod 777 /app/ssh/ssh_known_hosts
 
63
 
64
  # List contents of /etc/ssh and /app/ssh
65
  RUN ls -l /etc/ssh/ && \
@@ -67,10 +70,10 @@ RUN ls -l /etc/ssh/ && \
67
 
68
 
69
  # Create administrator group and admin user with full permissions
70
- RUN groupadd -f administrator && \
71
- id -u admin >/dev/null 2>&1 || useradd -m -s /bin/bash -G administrator,sudo admin && \
72
- echo 'admin:password' | chpasswd && \
73
- echo "%administrator ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
74
 
75
  # Install WebSSH dependencies
76
  RUN python3 -m venv /app/WebSSHEnv && \
@@ -95,4 +98,4 @@ EXPOSE 7860 2222
95
  #RUN chown -R admin:admin /home/admin
96
  RUN chmod -R 777 /app/* /home/*
97
  # Default command to keep the container running
98
- CMD ["/app/start.sh"]
 
37
  COPY . /app
38
 
39
  # Create necessary directories and set permissions
40
+ RUN mkdir -p /var/run/sshd /app /app/users/ssh /app/ssh && \
41
+ chmod -R 777 /app
42
+ # touch /etc/sudoers
43
 
44
  # Grant full sudo access to the 'administrator' group
45
  RUN sed -i 's/Defaults !requiretty/Defaults requiretty/' /etc/sudoers && \
 
61
  # Copy SSH keys to /app/ssh and set permissions
62
  RUN cp -r /etc/ssh/* /app/ssh && \
63
  chmod -R 777 /etc/ssh/* /app/ssh/* && \
64
+ touch /app/ssh/ssh_known_hosts && \
65
+ chmod 777 /app/ssh/ssh_known_hosts
66
 
67
  # List contents of /etc/ssh and /app/ssh
68
  RUN ls -l /etc/ssh/ && \
 
70
 
71
 
72
  # Create administrator group and admin user with full permissions
73
+ #RUN groupadd -f administrator && \
74
+ # id -u admin >/dev/null 2>&1 || useradd -m -s /bin/bash -G administrator,sudo admin && \
75
+ # echo 'admin:password' | chpasswd && \
76
+ # echo "%administrator ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
77
 
78
  # Install WebSSH dependencies
79
  RUN python3 -m venv /app/WebSSHEnv && \
 
98
  #RUN chown -R admin:admin /home/admin
99
  RUN chmod -R 777 /app/* /home/*
100
  # Default command to keep the container running
101
+ CMD ["/usr/sbin/sshd -p 2222 &&","/app/start.sh"]
WebSSH/Dockerfile CHANGED
@@ -42,15 +42,13 @@ RUN sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config &&
42
  echo "AllowUsers admin" >> /etc/ssh/sshd_config
43
 
44
 
45
- # Copy all the contents of /etc/ssh to /app/ssh
46
- RUN mkdir -p /app/ssh && cp -r /etc/ssh/* /app/ssh
47
-
48
 
49
  # Set the permissions for the SSH keys
50
  RUN chmod 777 /etc/ssh/ssh_host_* && \
51
  touch /app/ssh/ssh_known_hosts && \
52
  chmod 777 /app/ssh/ssh_* && \
53
- chmod 777 /home
 
54
 
55
  # List contents of /etc/ssh and /app/ssh
56
  RUN ls -l /etc/ssh/ && \
 
42
  echo "AllowUsers admin" >> /etc/ssh/sshd_config
43
 
44
 
 
 
 
45
 
46
  # Set the permissions for the SSH keys
47
  RUN chmod 777 /etc/ssh/ssh_host_* && \
48
  touch /app/ssh/ssh_known_hosts && \
49
  chmod 777 /app/ssh/ssh_* && \
50
+ chmod 777 /home && \
51
+ && cp -r /etc/ssh/* /app/ssh
52
 
53
  # List contents of /etc/ssh and /app/ssh
54
  RUN ls -l /etc/ssh/ && \
start.sh CHANGED
@@ -1,94 +1,127 @@
1
  #!/bin/bash
2
 
3
- # Print the current hostname and user details
4
- echo "* The hostname of this container is: $(cat /etc/hostname)"
5
- echo "* The Current User of this container is: $(whoami)"
6
- #echo "* The host of this container is: $(cat /etc/hosts)"
7
- echo "* ID of the user running the script: $(id -u) * Group: $(id -g) * Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')"
8
-
9
- # Switch to admin user and run a command
10
- echo "password" | su - admin -c "bash -i"
11
- # Commands to run as admin user
12
- echo "* Now running as: $(whoami)"
13
-
14
- # Ensure SSH host keys are present, generate if missing
15
- if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
16
- echo "* Generating SSH host keys *"
17
- ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ""
18
- ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N ""
19
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
20
- fi
21
-
22
- # Start SSH service if not running
23
- if ! pgrep -x "sshd" >/dev/null; then
24
- echo "* Starting SSH server on port 2222 *"
25
- /usr/sbin/sshd -p 2222
26
- else
27
- echo "* SSH server is already running *"
28
- fi
29
-
30
- # Check if 'admin' user exists, create if missing
31
- if ! id -u admin >/dev/null 2>&1; then
32
- echo "* Creating 'ubuntu' user *"
33
- useradd -m -s /bin/bash -G sudo admin
34
- echo "admin:password" | chpasswd
35
- #echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
36
- fi
37
-
38
- # Ensure 'admin' home directory permissions
39
- echo "* Fixing permissions for 'ubuntu' user *"
40
- chown -R admin:admin /home/admin
41
- chmod -R 777 /home/admin
42
-
43
- # Generate SSH keys for the 'admin' user if missing
44
- if [ ! -f /home/admin/.ssh/id_rsa ]; then
45
- echo "* Generating SSH keys for 'admin' user *"
46
- mkdir -p /home/admin/.ssh
47
- ssh-keygen -t rsa -b 2048 -f /app/users/ssh/id_rsa_admin -q -N ""
48
- ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N ""
49
- chown -R admin:admin /home/admin/.ssh
50
- chmod 700 /home/admin/.ssh
51
- chmod 600 /home/admin/.ssh/id_rsa
52
- chmod 644 /home/admin/.ssh/id_rsa.pub
53
- fi
54
-
55
- # Add public key to authorized_keys for 'admin' user
56
- if [ ! -f /home/admin/.ssh/authorized_keys ]; then
57
- echo "* Adding public key to authorized_keys for 'admin' user *"
58
- cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys
59
- chmod 777 /home/admin/.ssh/authorized_keys
60
- chown admin:admin /home/admin/.ssh/authorized_keys
61
- fi
62
-
63
-
64
- echo "* Contents of id_rsa:"
65
- cat /app/users/ssh/id_rsa_admin
66
-
67
- echo "* Contents of id_rsa of Admin:"
68
- cat /home/admin/.ssh/id_rsa
69
-
70
- # Print SSH server status
71
- echo "* Status of SSH service:"
72
- netstat -tuln
73
-
74
- # Activate virtual environment
75
- if [ -d "/app/WebSSHEnv" ]; then
76
- echo "* Activating virtual environment *"
77
- source /app/WebSSHEnv/bin/activate
78
- else
79
- echo "* Virtual environment not found, please check setup *"
80
- fi
81
-
82
- # Set working directory
83
- cd /app || exit
84
-
85
- # Print the contents of the working directory
86
- echo "* Contents of /app directory: *"
87
- ls -la /app
88
-
89
- # Run the WebSSH application
90
- echo "* Starting WebSSH application *"
91
- python3 -u -m WebSSH
92
-
93
- # Keep the container running
94
- tail -f /dev/null
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/bin/bash
2
 
3
+ # Function to print the current hostname and user details
4
+ print_host_details() {
5
+ echo "* The hostname of this container is: $(cat /etc/hostname)"
6
+ echo "* The host of this container is: $(cat /etc/hosts)"
7
+ echo "* ID of the user running the script: $(id -u) * Group: $(id -g) * Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')"
8
+ }
9
+
10
+ # Function to generate SSH host keys if missing
11
+ generate_ssh_keys() {
12
+ if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
13
+ echo "* Generating SSH host keys *"
14
+ ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; }
15
+ ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; }
16
+ ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; }
17
+ fi
18
+ }
19
+
20
+ # Function to start SSH service if not running
21
+ start_ssh_service() {
22
+ if ! pgrep -x "sshd" >/dev/null; then
23
+ echo "* Starting SSH server on port 2222 *"
24
+ /usr/sbin/sshd -p 2222 || { echo "Failed to start SSH server"; exit 1; }
25
+ else
26
+ echo "* SSH server is already running *"
27
+ fi
28
+ }
29
+
30
+ # Function to create 'admin' user if missing
31
+ create_admin_user() {
32
+ if ! id -u admin >/dev/null 2>&1; then
33
+ echo "* Creating 'admin' user *"
34
+ useradd -m -s /bin/bash -G sudo admin || { echo "Failed to create admin user"; exit 1; }
35
+ echo "admin:password" | chpasswd || { echo "Failed to set admin password"; exit 1; }
36
+ echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers || { echo "Failed to update sudoers"; exit 1; }
37
+ fi
38
+ }
39
+
40
+ # Function to fix permissions for 'admin' user
41
+ fix_admin_permissions() {
42
+ echo "* Fixing permissions for 'admin' user *"
43
+ chown -R admin:admin /home/admin || { echo "Failed to change ownership"; exit 1; }
44
+ chmod -R 700 /home/admin || { echo "Failed to set permissions"; exit 1; }
45
+ }
46
+
47
+ # Function to generate SSH keys for 'admin' user if missing
48
+ generate_admin_ssh_keys() {
49
+ if [ ! -f /home/admin/.ssh/id_rsa ]; then
50
+ echo "* Generating SSH keys for 'admin' user *"
51
+ sudo -u admin mkdir -p /home/admin/.ssh || { echo "Failed to create .ssh directory"; exit 1; }
52
+ sudo -u admin ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N "" || { echo "Failed to generate admin SSH key"; exit 1; }
53
+ chmod 700 /home/admin/.ssh || { echo "Failed to set .ssh directory permissions"; exit 1; }
54
+ chmod 600 /home/admin/.ssh/id_rsa || { echo "Failed to set private key permissions"; exit 1; }
55
+ chmod 644 /home/admin/.ssh/id_rsa.pub || { echo "Failed to set public key permissions"; exit 1; }
56
+ fi
57
+ }
58
+
59
+ # Function to add public key to authorized_keys for 'admin' user
60
+ add_admin_authorized_keys() {
61
+ if [ ! -f /home/admin/.ssh/authorized_keys ]; then
62
+ echo "* Adding public key to authorized_keys for 'admin' user *"
63
+ sudo -u admin bash -c "cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys" || { echo "Failed to add public key to authorized_keys"; exit 1; }
64
+ chmod 600 /home/admin/.ssh/authorized_keys || { echo "Failed to set authorized_keys permissions"; exit 1; }
65
+ fi
66
+ }
67
+
68
+ # Function to activate virtual environment
69
+ activate_virtual_env() {
70
+ if [ -d "/app/WebSSHEnv" ]; then
71
+ echo "* Activating virtual environment *"
72
+ source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
73
+ else
74
+ echo "* Virtual environment not found, please check setup *"
75
+ fi
76
+ }
77
+
78
+ # Function to set working directory
79
+ set_working_directory() {
80
+ cd /app || { echo "Failed to change directory to /app"; exit 1; }
81
+ }
82
+
83
+ # Function to print the contents of the working directory
84
+ print_working_directory_contents() {
85
+ echo "* Contents of /app directory: *"
86
+ ls -la /app
87
+ }
88
+
89
+ # Function to run the WebSSH application
90
+ run_webssh_application() {
91
+ echo "* Starting WebSSH application *"
92
+ python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; }
93
+ }
94
+ # Function to change account when username and password are given as parameters
95
+ change_account() {
96
+ local username=$1
97
+ local password=$2
98
+
99
+ if id -u "$username" >/dev/null 2>&1; then
100
+ echo "* Switching to user: $username *"
101
+ echo "$password" | sudo -S -u "$username" -i <<'EOF'
102
+ echo "* Now running as: $(whoami) *"
103
+ EOF
104
+ else
105
+ echo "User $username does not exist"
106
+ fi
107
+ }
108
+
109
+ # Function to keep the container running
110
+ keep_container_running() {
111
+ tail -f /dev/null
112
+ }
113
+
114
+ # Main script execution
115
+ print_host_details
116
+ generate_ssh_keys
117
+ #start_ssh_service
118
+ #create_admin_user
119
+ #fix_admin_permissions
120
+ change_account "admin" "password"
121
+ generate_admin_ssh_keys
122
+ add_admin_authorized_keys
123
+ activate_virtual_env
124
+ set_working_directory
125
+ print_working_directory_contents
126
+ run_webssh_application
127
+ keep_container_running
start_old.sh ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Print the current hostname and user details
4
+ echo "* The hostname of this container is: $(cat /etc/hostname)"
5
+ echo "* The Current User of this container is: $(whoami)"
6
+ #echo "* The host of this container is: $(cat /etc/hosts)"
7
+ echo "* ID of the user running the script: $(id -u) * Group: $(id -g) * Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')"
8
+
9
+ # Switch to admin user and run a command
10
+ echo "password" | su - admin -c "bash -i"
11
+ # Commands to run as admin user
12
+ echo "* Now running as: $(whoami)"
13
+
14
+ # Ensure SSH host keys are present, generate if missing
15
+ if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
16
+ echo "* Generating SSH host keys *"
17
+ ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ""
18
+ ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N ""
19
+ ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
20
+ fi
21
+
22
+ # Start SSH service if not running
23
+ if ! pgrep -x "sshd" >/dev/null; then
24
+ echo "* Starting SSH server on port 2222 *"
25
+ /usr/sbin/sshd -p 2222
26
+ else
27
+ echo "* SSH server is already running *"
28
+ fi
29
+
30
+ # Check if 'admin' user exists, create if missing
31
+ if ! id -u admin >/dev/null 2>&1; then
32
+ echo "* Creating 'ubuntu' user *"
33
+ useradd -m -s /bin/bash -G sudo admin
34
+ echo "admin:password" | chpasswd
35
+ #echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
36
+ fi
37
+
38
+ # Ensure 'admin' home directory permissions
39
+ echo "* Fixing permissions for 'ubuntu' user *"
40
+ chown -R admin:admin /home/admin
41
+ chmod -R 777 /home/admin
42
+
43
+ # Generate SSH keys for the 'admin' user if missing
44
+ if [ ! -f /home/admin/.ssh/id_rsa ]; then
45
+ echo "* Generating SSH keys for 'admin' user *"
46
+ mkdir -p /home/admin/.ssh
47
+ ssh-keygen -t rsa -b 2048 -f /app/users/ssh/id_rsa_admin -q -N ""
48
+ ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N ""
49
+ chown -R admin:admin /home/admin/.ssh
50
+ chmod 700 /home/admin/.ssh
51
+ chmod 600 /home/admin/.ssh/id_rsa
52
+ chmod 644 /home/admin/.ssh/id_rsa.pub
53
+ fi
54
+
55
+ # Add public key to authorized_keys for 'admin' user
56
+ if [ ! -f /home/admin/.ssh/authorized_keys ]; then
57
+ echo "* Adding public key to authorized_keys for 'admin' user *"
58
+ cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys
59
+ chmod 777 /home/admin/.ssh/authorized_keys
60
+ chown admin:admin /home/admin/.ssh/authorized_keys
61
+ fi
62
+
63
+
64
+ echo "* Contents of id_rsa:"
65
+ cat /app/users/ssh/id_rsa_admin
66
+
67
+ echo "* Contents of id_rsa of Admin:"
68
+ cat /home/admin/.ssh/id_rsa
69
+
70
+ # Print SSH server status
71
+ echo "* Status of SSH service:"
72
+ netstat -tuln
73
+
74
+ # Activate virtual environment
75
+ if [ -d "/app/WebSSHEnv" ]; then
76
+ echo "* Activating virtual environment *"
77
+ source /app/WebSSHEnv/bin/activate
78
+ else
79
+ echo "* Virtual environment not found, please check setup *"
80
+ fi
81
+
82
+ # Set working directory
83
+ cd /app || exit
84
+
85
+ # Print the contents of the working directory
86
+ echo "* Contents of /app directory: *"
87
+ ls -la /app
88
+
89
+ # Run the WebSSH application
90
+ echo "* Starting WebSSH application *"
91
+ python3 -u -m WebSSH
92
+
93
+ # Keep the container running
94
+ tail -f /dev/null
start_upgrade.sh DELETED
@@ -1,112 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Function to print the current hostname and user details
4
- print_host_details() {
5
- echo "* The hostname of this container is: $(cat /etc/hostname)"
6
- echo "* The host of this container is: $(cat /etc/hosts)"
7
- echo "* ID of the user running the script: $(id -u) * Group: $(id -g) * Status of Admin: $(id admin 2>/dev/null || echo 'Admin user not found')"
8
- }
9
-
10
- # Function to generate SSH host keys if missing
11
- generate_ssh_keys() {
12
- if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
13
- echo "* Generating SSH host keys *"
14
- ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; }
15
- ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; }
16
- ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; }
17
- fi
18
- }
19
-
20
- # Function to start SSH service if not running
21
- start_ssh_service() {
22
- if ! pgrep -x "sshd" >/dev/null; then
23
- echo "* Starting SSH server on port 2222 *"
24
- /usr/sbin/sshd -p 2222 || { echo "Failed to start SSH server"; exit 1; }
25
- else
26
- echo "* SSH server is already running *"
27
- fi
28
- }
29
-
30
- # Function to create 'admin' user if missing
31
- create_admin_user() {
32
- if ! id -u admin >/dev/null 2>&1; then
33
- echo "* Creating 'admin' user *"
34
- useradd -m -s /bin/bash -G sudo admin || { echo "Failed to create admin user"; exit 1; }
35
- echo "admin:password" | chpasswd || { echo "Failed to set admin password"; exit 1; }
36
- echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers || { echo "Failed to update sudoers"; exit 1; }
37
- fi
38
- }
39
-
40
- # Function to fix permissions for 'admin' user
41
- fix_admin_permissions() {
42
- echo "* Fixing permissions for 'admin' user *"
43
- chown -R admin:admin /home/admin || { echo "Failed to change ownership"; exit 1; }
44
- chmod -R 700 /home/admin || { echo "Failed to set permissions"; exit 1; }
45
- }
46
-
47
- # Function to generate SSH keys for 'admin' user if missing
48
- generate_admin_ssh_keys() {
49
- if [ ! -f /home/admin/.ssh/id_rsa ]; then
50
- echo "* Generating SSH keys for 'admin' user *"
51
- sudo -u admin mkdir -p /home/admin/.ssh || { echo "Failed to create .ssh directory"; exit 1; }
52
- sudo -u admin ssh-keygen -t rsa -b 2048 -f /home/admin/.ssh/id_rsa -q -N "" || { echo "Failed to generate admin SSH key"; exit 1; }
53
- chmod 700 /home/admin/.ssh || { echo "Failed to set .ssh directory permissions"; exit 1; }
54
- chmod 600 /home/admin/.ssh/id_rsa || { echo "Failed to set private key permissions"; exit 1; }
55
- chmod 644 /home/admin/.ssh/id_rsa.pub || { echo "Failed to set public key permissions"; exit 1; }
56
- fi
57
- }
58
-
59
- # Function to add public key to authorized_keys for 'admin' user
60
- add_admin_authorized_keys() {
61
- if [ ! -f /home/admin/.ssh/authorized_keys ]; then
62
- echo "* Adding public key to authorized_keys for 'admin' user *"
63
- sudo -u admin bash -c "cat /home/admin/.ssh/id_rsa.pub >> /home/admin/.ssh/authorized_keys" || { echo "Failed to add public key to authorized_keys"; exit 1; }
64
- chmod 600 /home/admin/.ssh/authorized_keys || { echo "Failed to set authorized_keys permissions"; exit 1; }
65
- fi
66
- }
67
-
68
- # Function to activate virtual environment
69
- activate_virtual_env() {
70
- if [ -d "/app/WebSSHEnv" ]; then
71
- echo "* Activating virtual environment *"
72
- source /app/WebSSHEnv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
73
- else
74
- echo "* Virtual environment not found, please check setup *"
75
- fi
76
- }
77
-
78
- # Function to set working directory
79
- set_working_directory() {
80
- cd /app || { echo "Failed to change directory to /app"; exit 1; }
81
- }
82
-
83
- # Function to print the contents of the working directory
84
- print_working_directory_contents() {
85
- echo "* Contents of /app directory: *"
86
- ls -la /app
87
- }
88
-
89
- # Function to run the WebSSH application
90
- run_webssh_application() {
91
- echo "* Starting WebSSH application *"
92
- python3 -u -m WebSSH || { echo "Failed to start WebSSH application"; exit 1; }
93
- }
94
-
95
- # Function to keep the container running
96
- keep_container_running() {
97
- tail -f /dev/null
98
- }
99
-
100
- # Main script execution
101
- print_host_details
102
- generate_ssh_keys
103
- start_ssh_service
104
- create_admin_user
105
- fix_admin_permissions
106
- generate_admin_ssh_keys
107
- add_admin_authorized_keys
108
- activate_virtual_env
109
- set_working_directory
110
- print_working_directory_contents
111
- run_webssh_application
112
- keep_container_running