-
-
Save chiefdeals/26db39badc284d4fe4576896c512b8bf 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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