LibrePortal/scripts/ssh/keys/setup_auth_key.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

41 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
setupSSHAuthorizedKeys()
{
local username="$1"
local public_key_full="$2"
if [[ "$username" == "root" ]]; then
local ssh_path="/root/.ssh"
else
local ssh_path="/home/$username/.ssh"
fi
# Check if the directory exists; if not, create it
if [ ! -d "$ssh_path" ]; then
local result=$(createFolders "loud" $username $ssh_path)
checkSuccess "Creating $(basename "$private_key_path") folder"
result=$(sudo chmod 700 $ssh_path)
checkSuccess "Updating permissions for $ssh_path"
else
result=$(sudo chmod 700 $ssh_path)
checkSuccess "Updating permissions for $ssh_path"
fi
if [ -f "${ssh_path}/authorized_keys" ]; then
result=$(sudo rm ${ssh_path}/authorized_keys)
checkSuccess "Deleted old authorized_keys file for user $username"
fi
result=$(sudo cp "$public_key_full" "${ssh_path}/authorized_keys")
checkSuccess "Adding $(basename $public_key_full) to the Authorized_keys file for user $username"
result=$(sudo chmod 600 ${ssh_path}/authorized_keys)
checkSuccess "Updating permissions for ${username}'s authorized_keys file."
updateFileOwnership "${ssh_path}/authorized_keys" $username $username
result=$(sudo systemctl reload ssh)
checkSuccess "Reloading SSH service"
}