Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Created November 23, 2017 03:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hongkongkiwi/733805f42ba5f4f801e18b77453019dc to your computer and use it in GitHub Desktop.
Save hongkongkiwi/733805f42ba5f4f801e18b77453019dc to your computer and use it in GitHub Desktop.
Small script to setup ssh keys and configs on Unraid to persist after boot. Supports multiple users.
#!/bin/bash
# Add this line into /boot/config/go where username is the user you want to setup, probably root
#/boot/config/ssh/setup_ssh_client.sh "username"
if [[ "$1" == "" ]]; then
echo "Invalid User!"
exit 1
fi
if [[ ! -d "/boot/config/ssh/user_configs" ]]; then
echo "User Configs Dir doesn't exist!"
echo "/boot/config/ssh/user_configs"
exit 2
fi
if [[ ! -d "/boot/config/ssh/user_configs/${1}" ]]; then
mkdir "/boot/config/ssh/user_configs/${1}"
echo "Empty ssh user configs directory"
fi
if [[ "$1" == "root" ]]; then
USER_DIR="/root"
else
USER_DIR="/home/${1}"
fi
SSH_DIR="${USER_DIR}/.ssh"
ssh_files=( "id_rsa" "id_rsa.pub" "config" "authorized_keys" )
mkdir -p "${SSH_DIR}"
chown "$1" "${SSH_DIR}"
chmod 755 "${SSH_DIR}"
for ssh_file in "${ssh_files[@]}"
do
:
if [[ -f "/boot/config/ssh/user_configs/${1}/${ssh_file}" ]]; then
cp "/boot/config/ssh/user_configs/${1}/${ssh_file}" "${SSH_DIR}/${ssh_file}"
chmod 600 "${SSH_DIR}/${ssh_file}"
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment