@@ -5,20 +5,53 @@ echo "Exporting environment variables..."
5
5
printenv | grep -E ' ^RUNPOD_|^PATH=|^_=' | sed ' s/^\(.*\)=\(.*\)$/export \1="\2"/' >> /etc/rp_environment
6
6
echo ' source /etc/rp_environment' >> ~ /.bashrc
7
7
8
- if [[ $PUBLIC_KEY ]]; then
9
- # runpod
8
+ add_keys_to_authorized () {
9
+ local key_value=$1
10
+
11
+ # Create the ~/.ssh directory and set permissions
10
12
mkdir -p ~ /.ssh
11
13
chmod 700 ~ /.ssh
12
- echo $PUBLIC_KEY >> ~ /.ssh/authorized_keys
14
+
15
+ # Create the authorized_keys file if it doesn't exist
16
+ touch ~ /.ssh/authorized_keys
17
+
18
+ # Initialize an empty key variable
19
+ local key=" "
20
+
21
+ # Read the key variable word by word
22
+ for word in $key_value ; do
23
+ # Check if the word looks like the start of a key
24
+ if [[ $word == ssh-* ]]; then
25
+ # If there's a key being built, add it to the authorized_keys file
26
+ if [[ -n $key ]]; then
27
+ echo $key >> ~ /.ssh/authorized_keys
28
+ fi
29
+ # Start a new key
30
+ key=$word
31
+ else
32
+ # Append the word to the current key
33
+ key=" $key $word "
34
+ fi
35
+ done
36
+
37
+ # Add the last key to the authorized_keys file
38
+ if [[ -n $key ]]; then
39
+ echo $key >> ~ /.ssh/authorized_keys
40
+ fi
41
+
42
+ # Set the correct permissions
43
+ chmod 600 ~ /.ssh/authorized_keys
13
44
chmod 700 -R ~ /.ssh
45
+ }
46
+
47
+ if [[ $PUBLIC_KEY ]]; then
48
+ # runpod
49
+ add_keys_to_authorized " $PUBLIC_KEY "
14
50
# Start the SSH service in the background
15
51
service ssh start
16
- elif [ -n " $SSH_KEY " ]; then
52
+ elif [[ $SSH_KEY ] ]; then
17
53
# latitude.sh
18
- mkdir -p ~ /.ssh
19
- chmod 700 ~ /.ssh
20
- echo $SSH_KEY >> ~ /.ssh/authorized_keys
21
- chmod 700 -R ~ /.ssh
54
+ add_keys_to_authorized " $SSH_KEY "
22
55
# Start the SSH service in the background
23
56
service ssh start
24
57
else
0 commit comments