mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
added ssh-copy-id plugin for use on machines without it built-in
This commit is contained in:
parent
1120f97305
commit
10bdcb3951
1 changed files with 53 additions and 0 deletions
53
plugins/ssh-copy-id/ssh-copy-id.plugin.zsh
Normal file
53
plugins/ssh-copy-id/ssh-copy-id.plugin.zsh
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
# There's probably a better way to define this if
|
||||||
|
ssh-upload-id () {
|
||||||
|
RSAKEY="${HOME}/.ssh/id_rsa.pub"
|
||||||
|
DSAKEY="${HOME}/.ssh/id_dsa.pub"
|
||||||
|
|
||||||
|
if [ $# -eq 2 ]; then
|
||||||
|
KEY=$1
|
||||||
|
if [ ! -r $KEY ]
|
||||||
|
then
|
||||||
|
echo "'$KEY' does not exist or is not readable"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
SERVER=$2
|
||||||
|
else
|
||||||
|
if [ -r ${RSAKEY} ]; then
|
||||||
|
KEY=$RSAKEY
|
||||||
|
elif [ -r ${DSAKEY} ]; then
|
||||||
|
KEY=$RSAKEY
|
||||||
|
else
|
||||||
|
echo "No RSA or DSA key found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
SERVER=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# -lt 1 -o "$1" = "-h" ]; then
|
||||||
|
echo "Usage: $0 [publickey_file] [user@]machine"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# testing above
|
||||||
|
|
||||||
|
echo "Copying $KEY to $SERVER"
|
||||||
|
|
||||||
|
cat $KEY | \
|
||||||
|
ssh $SERVER 'mkdir -p -m 0700 ${HOME}/.ssh && \
|
||||||
|
cat >> $HOME/.ssh/authorized_keys && \
|
||||||
|
chmod 0600 $HOME/.ssh/authorized_keys'
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Public key installed on $SERVER"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "Sorry, an error occurred!"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# alias it to ssh-copy-id if it doesn't exist, like on OS X
|
||||||
|
EXISTING_CHECK=`which ssh-copy-id`
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
alias ssh-copy-id=ssh-upload-id
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue