Last active
April 21, 2016 15:48
-
-
Save smsharma/23b5aa9f54f2427a2432e5afe269901c to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# create ssh connections without giving a password | |
if [ $# -lt 1 ]; then | |
echo Usage: $0 username@remotehost | |
exit | |
fi | |
remote="$1" # 1st command-line argument is the user@remotehost address | |
this=$HOST # name of client host | |
# first check if we need to run ssh-keygen for generating | |
# $HOME/.ssh with public and private keys: | |
if [ ! -d $HOME/.ssh ]; then | |
echo "just type RETURN for each question:" # no passphrase - unsecure!! | |
# generate RSA1, RSA and DSA keys: | |
echo; echo; echo | |
ssh-keygen -t rsa1 | |
echo; echo; echo | |
ssh-keygen -t rsa | |
echo; echo; echo | |
ssh-keygen -t dsa | |
else | |
# we have $HOME/.ssh, but check that we have all types of | |
# keys (RSA1, RSA, DSA): | |
if [ ! -f $HOME/.ssh/identity ]; then | |
# generate RSA1 keys: | |
echo "just type RETURN for each question:" # no passphrase - unsecure!! | |
ssh-keygen -t rsa1 | |
fi | |
if [ ! -f $HOME/.ssh/id_rsa ]; then | |
# generate RSA keys: | |
echo "just type RETURN for each question:" # no passphrase - unsecure!! | |
ssh-keygen -t rsa | |
fi | |
if [ ! -f $HOME/.ssh/id_rsa ]; then | |
# generate DSA keys: | |
echo "just type RETURN for each question:" # no passphrase - unsecure!! | |
ssh-keygen -t dsa | |
fi | |
fi | |
cd $HOME/.ssh | |
if [ ! -f config ]; then | |
# make ssh try ssh -1 (RSA1 keys) first and then ssh -2 (DSA keys) | |
echo "Protocol 1,2" > config | |
fi | |
# copy public keys (all three types) to the destination host: | |
echo; echo; echo | |
# create .ssh on remote host if it's not there: | |
ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi' | |
# copy RSA1 key: | |
scp identity.pub ${remote}:.ssh/${this}_rsa1.pub | |
# copy RSA key: | |
#scp id_rsa.pub ${remote}:.ssh/${this}_rsa.pub | |
# copy DSA key: | |
scp id_dsa.pub ${remote}:.ssh/${this}_dsa.pub | |
# make authorized_keys(2) files on remote host: | |
echo; echo; echo | |
# this one copies all three keys: | |
#ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_rsa.pub >> authorized_keys2; cat ${this}_dsa.pub >> authorized_keys2;" | |
# this one copies RSA1 and DSA keys: | |
ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_dsa.pub >> authorized_keys2;" | |
echo; echo; echo | |
echo "try an ssh $remote" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment