#!/bin/bash

export REMOTE_USER=${USER}
export REMOTE_HOST=$1
export REMOTE_PORT=$2

# The following is generated by the above variables. No tweaks necessary.
export KEY_NAME=~/.ssh/id_${REMOTE_USER}_${REMOTE_HOST}
export KEY_COMMENT="${USER}@${HOSTNAME}:${REMOTE_USER}@${REMOTE_HOST}"

ssh-keygen -C ${KEY_COMMENT} -f ${KEY_NAME} -t ed25519

cat <<EOF >> ~/.ssh/config

Host ${REMOTE_HOST}
    Hostname ${REMOTE_HOST}
    IdentityFile ${KEY_NAME}
    User ${REMOTE_USER}
    Port ${REMOTE_PORT:=22}
EOF