fix setting the authorized keys when there are more than one in the env var (#1626)
This commit is contained in:
@@ -5,20 +5,53 @@ echo "Exporting environment variables..."
|
||||
printenv | grep -E '^RUNPOD_|^PATH=|^_=' | sed 's/^\(.*\)=\(.*\)$/export \1="\2"/' >> /etc/rp_environment
|
||||
echo 'source /etc/rp_environment' >> ~/.bashrc
|
||||
|
||||
add_keys_to_authorized() {
|
||||
local key_value=$1
|
||||
|
||||
# Create the ~/.ssh directory and set permissions
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
|
||||
# Create the authorized_keys file if it doesn't exist
|
||||
touch ~/.ssh/authorized_keys
|
||||
|
||||
# Initialize an empty key variable
|
||||
local key=""
|
||||
|
||||
# Read the key variable word by word
|
||||
for word in $key_value; do
|
||||
# Check if the word looks like the start of a key
|
||||
if [[ $word == ssh-* ]]; then
|
||||
# If there's a key being built, add it to the authorized_keys file
|
||||
if [[ -n $key ]]; then
|
||||
echo $key >> ~/.ssh/authorized_keys
|
||||
fi
|
||||
# Start a new key
|
||||
key=$word
|
||||
else
|
||||
# Append the word to the current key
|
||||
key="$key $word"
|
||||
fi
|
||||
done
|
||||
|
||||
# Add the last key to the authorized_keys file
|
||||
if [[ -n $key ]]; then
|
||||
echo $key >> ~/.ssh/authorized_keys
|
||||
fi
|
||||
|
||||
# Set the correct permissions
|
||||
chmod 600 ~/.ssh/authorized_keys
|
||||
chmod 700 -R ~/.ssh
|
||||
}
|
||||
|
||||
if [[ $PUBLIC_KEY ]]; then
|
||||
# runpod
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo $PUBLIC_KEY >> ~/.ssh/authorized_keys
|
||||
chmod 700 -R ~/.ssh
|
||||
add_keys_to_authorized "$PUBLIC_KEY"
|
||||
# Start the SSH service in the background
|
||||
service ssh start
|
||||
elif [ -n "$SSH_KEY" ]; then
|
||||
elif [[ $SSH_KEY ]]; then
|
||||
# latitude.sh
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo $SSH_KEY >> ~/.ssh/authorized_keys
|
||||
chmod 700 -R ~/.ssh
|
||||
add_keys_to_authorized "$SSH_KEY"
|
||||
# Start the SSH service in the background
|
||||
service ssh start
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user