Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ssh keygen stuff functions
# https://github.com/curtisalexander/til/blob/master/cl/ssh-config.md
# host="${1#*@}"
# user="${1%@*}"
function ssh_keygen(){
ssh-keygen -t rsa -b 4096 -N "" -C "$USER@$HOSTNAME to $1" -f ~/.ssh/"$1_id_rsa"
pub_key $1
}
function pub_key(){
pbcopy < ~/.ssh/"$1_id_rsa.pub"
}
ssh_setup_key(){
ssh_keygen "$@"
# ssh_copy_id $@
# pub_key $@
}
# <User@HostName><username>
# git@github.com tarranjones
# git@github.com otheraccount
# git@bitbucket.org tarranjones
# git@bitbucket.org otheraccount
ssh_copy_id(){
if ! [ command -v "ssh-copy-id" >/dev/null 2>&1 ] ; then
ssh-copy-id -i ~/.ssh/"${1:+$1_}${2:+($2)_}id_rsa.pub" $1
else
cat ~/.ssh/"${1:+$1_}${2:+($2)_}id_rsa.pub" | ssh $1 'umask 0077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys && echo "Key copied"'
fi
}
# <username@HostName>
# tarranjones@github.com
pub_key(){
pbcopy < ~/.ssh/"$1_id_rsa.pub"
}
# <Host> <HostName> <User> <IdentityFile>
# git@github.com-tarranjones github.com git ~/.ssh/git@github.com_(tarranjones)id_rsa"
ssh_config_host(){
mkdir -p ~/.ssh
# // this will create duplicate entiries - needs improving
# further reading - https://gist.github.com/jexchan/2351996/de8ad280bef07c668fe55486e2bca546079efdc8
# ssh_config docs - https://linux.die.net/man/5/ssh_config
echo -e "Host $1\n\tHostName $2\n\tPreferredAuthentications publickey\n\t${3:+User $3\n\t}${4:+IdentityFile $4\n\t}" >> ~/.ssh/config
}
# ssh_setup_key tarranjones@bitbucket.org
# ssh_setup_key tarranjones@github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment