vim, gitconfig, update.sh
[dotfiles_afify.git] / .scripts / ssh.sh
blobd8f7b6a90e54b05f67ce1889fe5140e5f115d406
1 #!/bin/sh
3 email="hassan@afify.dev"
4 server=$2
5 ssh_dir=$HOME/.ssh
6 selected_key=
8 select_key(){
9 case $1 in
10 public) ktype='public' ;;
11 private) ktype='private' not='!' ;;
12 esac
13 selected_key=$(find $ssh_dir -type f $not -iname "*.pub" !\
14 -name "config" ! -name "known_hosts" |\
15 dmenu -l 10 -p "Select $ktype ssh key: ")
18 clipb(){
19 tr -d '\n' | xclip -sel clip
22 case $1 in
23 gen) time ssh-keygen -t ed25519 -a 100 -C $email -f $ssh_dir/$server
24 clipb $ssh_dir/$server.pub
25 printf "\n# $server.com\nHost $server.com
26 IdentityFile $ssh_dir/$server" | tr -d '\t' >> $ssh_dir/config ;;
27 rsa_gen) ssh-keygen -t rsa -b 4096 -C $email -f $ssh_dir/$server ;;
28 public) select_key public; cat $selected_key | clipb ;;
29 private) select_key private; cat $selected_key | clipb ;;
30 pass) select_key private; ssh-keygen -p -f $selected_key ;;
31 finger) select_key public; ssh-keygen -l -E md5 -f $selected_key | clipb;;
32 send) select_key public; ssh-copy-id -i $selected_key -f $server ;;
33 esac