-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh-authorize
executable file
·34 lines (29 loc) · 1.01 KB
/
ssh-authorize
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
#!/bin/bash
## Usage: ssh-authorize [user@]hostname
##
## Create and place DSA public key on a remote ssh server. Establishes
## an automatic public key private key authentication.
##
## Your default DSA key will be created and(or) used. Keep the default name:
## $HOME/.ssh/id_dsa.pub
if test "$1" == "help" || test "$#" -eq 0
then
sh $(dirname $0)/prj-usage $0
exit 1
fi
user_host=$1
shift 1
if [[ ! $user_host =~ "@" ]]
then
alias=$user_host
. $(dirname $0)/prj-env $alias,user,host
user_host=$user${user:+@}$host
fi
# We have to have a key first
sh $(dirname $0)/ssh-keygen-default
# Double test, was the key created?
[ -f $HOME/.ssh/id_dsa.pub ] && \
# Create .ssh, and only if it was just created, set the permissions
# Upload the local public key and append it to remote's authorized_keys file
ssh $user_host $* mkdir -p .ssh \&\& chmod 700 .ssh\; echo "`cat $HOME/.ssh/id_dsa.pub` >> .ssh/authorized_keys && ln -s .ssh/authorized_keys .ssh/authorized_keys2" &&
echo SSH Link established...