-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh
88 lines (71 loc) · 2.39 KB
/
ssh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /usr/bin/env bash
#ssh agent
alias lock='echo "KEYINFO --ssh-list --ssh-fpr" | gpg-connect-agent | grep 'MD5' | print 3 | while read KEY; do echo "DELETE_KEY $KEY" | gpg-connect-agent; done'
alias list='ssh-add -l'
#GPG Agent running as ssh-agent
if [ -z $SSH_AUTH_SOCK ]; then
GPG_AUTH_SOCK_FILENAME=/run/user/`id -u`/gnupg/S.gpg-agent.ssh;
if [ -S $GPG_AUTH_SOCK_FILENAME ] ; then
export SSH_AUTH_SOCK=$GPG_AUTH_SOCK_FILENAME
alias lock='echo > ~/.gnupg/sshcontrol'
fi
fi
# auto-start keychain
#if which keychain &> /dev/null; then
# eval `keychain --inherit any --agents ssh --quick --quiet --eval`
#fi
# bash completion for ssh config
if [ -f ~/.ssh/config ]; then
complete -W "$(cat ~/.ssh/config 2>/dev/null | grep "Host \w" | cut -f 2 -d ' ')" ssh
complete -W "$(cat ~/.ssh/config 2>/dev/null | grep "Host \w" | cut -f 2 -d ' ')" sshow
fi
# functions
function sshclear { if [ $1 -gt "0" ]; then REGEXP="${1}d"; sed -i".bak" $REGEXP ~/.ssh/known_hosts; fi }
if [ -d $PASSWORD_STORE_DIR/ssh ]; then
function add {
rm sshfifo
mkfifo -m 0600 sshfifo
pass ssh/$1 >sshfifo | ssh-add sshfifo
rm sshfifo
}
complete -W "$(ls $PASSWORD_STORE_DIR/ssh/*.*sa.gpg 2>/dev/null| sed -e 's/.*\///' -e 's/.gpg$//')" add
else if [ -d $HOME/.ssh/ ]; then
complete -W "$(ls ~/.ssh/*.*sa 2>/dev/null| sed -e 's/.*\///' | cut -f 1 -d '.')" add
function add {
FILELIST="$HOME/.ssh/key.rsa"
for ARG in $*; do
FILELIST="$FILELIST $HOME/.ssh/$ARG.*sa";
done
ssh-add $FILELIST
}
fi
fi
function sshow {
for ARG in $*; do
grep -A 1 $ARG ~/.ssh/config
done
}
#aliases
alias deskpi='ssh -A [email protected]'
alias callisto='ssh -A [email protected]'
#host specific commands
# Add bash completion for ssh: it tries to complete the host to which you
# want to connect from the list of the ones contained in ~/.ssh/known_hosts
#__ssh_known_hosts() {
# if [[ -f ~/.ssh/known_hosts ]]; then
# cut -d " " -f1 ~/.ssh/known_hosts | cut -d "," -f1
# fi
#}
#_ssh() {
# local cur known_hosts
# COMPREPLY=()
# cur="${COMP_WORDS[COMP_CWORD]}"
# known_hosts="$(__ssh_known_hosts)"
#
# if [[ ! ${cur} == -* ]] ; then
# COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur}) )
# return 0
# fi
#}
#complete -o bashdefault -o default -o nospace -F _ssh ssh 2>/dev/null \
# || complete -o default -o nospace -F _ssh ssh