Created
March 2, 2017 09:24
-
-
Save tarranjones/1a73dacf13f031dc6f2c807c144de2c2 to your computer and use it in GitHub Desktop.
ssh keygen stuff functions
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
# 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> | |
# [email protected] tarranjones | |
# [email protected] otheraccount | |
# [email protected] tarranjones | |
# [email protected] 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> | |
# [email protected] | |
pub_key(){ | |
pbcopy < ~/.ssh/"$1_id_rsa.pub" | |
} | |
# <Host> <HostName> <User> <IdentityFile> | |
# [email protected] github.com git ~/.ssh/[email protected]_(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 [email protected] | |
# ssh_setup_key [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment