Skip to content

Commit caf1d12

Browse files
committed
refactor: use mounting authorized_keys
1 parent 7779b6b commit caf1d12

File tree

4 files changed

+5
-40
lines changed

4 files changed

+5
-40
lines changed

OS/debian-ssh/12.6/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ RUN chmod +x /usr/start/startup.sh && \
1717
echo 'GatewayPorts yes' >> /etc/ssh/sshd_config && \
1818
echo 'X11Forwarding yes' >> /etc/ssh/sshd_config && \
1919
echo 'Port 22' >> /etc/ssh/sshd_config && \
20+
echo 'AuthorizedKeysFile /usr/start/authorized_keys .ssh/authorized_keys .ssh/authorized_keys2' >> /etc/ssh/sshd_config && \
2021
useradd -m -s /bin/bash devbox && \
2122
usermod -aG sudo devbox && \
2223
echo 'devbox ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers && \
2324
rm -rf /tmp/* && \
2425
mkdir -p /home/devbox/.ssh && \
26+
echo "devbox:devbox" | sudo chpasswd && \
2527
chown -R devbox:devbox /home/devbox/.ssh && \
2628
chmod -R 770 /home/devbox/.ssh
2729

configs/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
php=8.2.20
2-
node.js=22
2+
node.js=22

script/clean_unused_runtime.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REFERENCED_RUNTIMES="referenced_runtimes.txt"
44
DEPRECATED_RUNTIMES="deprecated_runtimes.txt"
55

66
kubectl get devbox -A -o json | jq -r '.items[].spec.runtimeRef.name' | sort | uniq > "$REFERENCED_RUNTIMES"
7-
kubectl get runtime -A -o json | jq -r '.items[] | select(.spec.state == "deprecated") | .metadata.name' | sort | uniq > "$DEPRECATED_RUNTIMES"
7+
kubectl get runtime -n devbox-system -o json | jq -r '.items[] | select(.spec.state == "deprecated") | .metadata.name' | sort | uniq > "$DEPRECATED_RUNTIMES"
88

99
UNREFERENCED_RUNTIMES=$(comm -13 "$REFERENCED_RUNTIMES" "$DEPRECATED_RUNTIMES")
1010

@@ -14,7 +14,7 @@ echo "$UNREFERENCED_RUNTIMES"
1414
if [ ! -z "$UNREFERENCED_RUNTIMES" ]; then
1515
echo "正在删除未被引用的 deprecated runtime..."
1616
for runtime in $UNREFERENCED_RUNTIMES; do
17-
kubectl delete runtime "$runtime" --all-namespaces
17+
kubectl delete runtime "$runtime" -n devbox-system
1818
done
1919
else
2020
echo "没有未被引用的 deprecated runtime 需要删除。"

script/startup.sh

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,5 @@
11
#!/bin/bash
22

3-
# Define the password file location
4-
PASSWORD_FILE="/usr/start/user_password.txt"
5-
6-
if [ ! -z "${SEALOS_DEVBOX_NEED_INIT}" ] && [ "${SEALOS_DEVBOX_NEED_INIT}" == "true" ]; then
7-
if [ -d "/home/devbox/.ssh" ]; then
8-
cd /home/devbox/.ssh
9-
rm -rf ./*
10-
fi
11-
if [ -f "/usr/start/user_password.txt" ]; then
12-
rm /usr/start/user_password.txt
13-
fi
14-
fi
15-
16-
# Check if the password file exists
17-
if [ ! -f "${PASSWORD_FILE}" ]; then
18-
# If the password file doesn't exist, check if USER_PASSWORD is already set
19-
if [ -z "${SEALOS_DEVBOX_PASSWORD}" ]; then
20-
# If USER_PASSWORD is not set, generate a random 8-character password
21-
SEALOS_DEVBOX_PASSWORD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c8)
22-
fi
23-
# Save the generated or existing USER_PASSWORD to the password file
24-
touch "${PASSWORD_FILE}"
25-
# Set the password for the 'sealos' user
26-
echo "devbox:${SEALOS_DEVBOX_PASSWORD}" | sudo chpasswd
27-
# Display the password for logging purposes (optional)
28-
echo "SEALOS_DEVBOX_PASSWORD=${SEALOS_DEVBOX_PASSWORD}"
29-
fi
30-
31-
if [ -f /usr/start/.ssh/id.pub ]; then
32-
public_key=$(cat /usr/start/.ssh/id.pub)
33-
if ! grep -qF "$public_key" /home/devbox/.ssh/authorized_keys 2>/dev/null; then
34-
mkdir -p /home/devbox/.ssh
35-
echo "$public_key" >> /home/devbox/.ssh/authorized_keys
36-
echo "Public key successfully added to authorized_keys"
37-
fi
38-
fi
39-
403
if [ ! -z "${SEALOS_DEVBOX_NAME}" ]; then
414
echo "${SEALOS_DEVBOX_NAME}">/etc/hostname
425
fi

0 commit comments

Comments
 (0)