BinaryONe commited on
Commit
e69d427
·
1 Parent(s): 284c6f8
Files changed (2) hide show
  1. Dockerfile +4 -1
  2. start.sh +9 -7
Dockerfile CHANGED
@@ -40,7 +40,10 @@ COPY . /app
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 echo "%administrator ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
 
 
 
44
 
45
  # Generate SSH host keys
46
  RUN ssh-keygen -A
 
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 && \
44
+ echo 'admin ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
45
+ echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
46
+ #RUN echo "%administrator ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
47
 
48
  # Generate SSH host keys
49
  RUN ssh-keygen -A
start.sh CHANGED
@@ -3,14 +3,13 @@
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" | sudo -S -u admin -i <<'EOF'
11
  # Commands to run as admin user
12
  echo "* Now running as: $(whoami)"
13
- EOF
14
 
15
  # Ensure SSH host keys are present, generate if missing
16
  if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
@@ -30,16 +29,16 @@ fi
30
 
31
  # Check if 'admin' user exists, create if missing
32
  if ! id -u admin >/dev/null 2>&1; then
33
- echo "* Creating 'admin' user *"
34
  useradd -m -s /bin/bash -G sudo admin
35
  echo "admin:password" | chpasswd
36
- echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
37
  fi
38
 
39
  # Ensure 'admin' home directory permissions
40
- echo "* Fixing permissions for 'admin' user *"
41
  chown -R admin:admin /home/admin
42
- chmod -R 700 /home/admin
43
 
44
  # Generate SSH keys for the 'admin' user if missing
45
  if [ ! -f /home/admin/.ssh/id_rsa ]; then
@@ -65,6 +64,9 @@ fi
65
  echo "* Contents of id_rsa:"
66
  cat /app/users/ssh/id_rsa_admin
67
 
 
 
 
68
  # Print SSH server status
69
  echo "* Status of SSH service:"
70
  netstat -tuln
 
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
 
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
 
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