Welcome to kriss.run!


Back

ssh_setup.sh

#!/usr/bin/env bash

ssh_src_dir="/usr/local/share/ssh"
ssh_dst_dir="$HOME/.ssh"

echo "Installing SSH keys from $ssh_src_dir to $ssh_dst_dir"

if [[ ! -d "$ssh_src_dir" ]]; then
    echo "Source folder for SSH keys not found ($ssh_src_dir)"
    return 1
fi

if [[ ! -d "$ssh_dst_dir" ]]; then
    echo "Destination folder $ssh_dst_dir does not exist, creating..."
    mkdir -p "$ssh_dst_dir"
fi

cp "$ssh_src_dir"/* "$ssh_dst_dir"
chmod -R 755 "$ssh_dst_dir"
chmod 644 "$ssh_dst_dir"/*.pub
chmod 600 "$ssh_dst_dir"/*_rsa
chmod 600 "$ssh_dst_dir"/*_dsa
chmod 600 "$ssh_dst_dir"/*_ecdsa
chmod 600 "$ssh_dst_dir"/*_ed25519

for key in "$ssh_dst_dir"/*_rsa "$ssh_dst_dir"/*_dsa "$ssh_dst_dir"/*_ecdsa "$ssh_dst_dir"/*_ed25519; do
	ssh-add "$key"
done