Don't be destructive to previous ssh keys

This commit is contained in:
DarkFeather 2017-03-30 12:44:53 -05:00
parent 319a4a302a
commit f3c07b7c3a

View File

@ -16,7 +16,7 @@ tput setaf 2; tput bold; printf "$system ($realname) ... \n"; tput sgr0;
# Find the Private key to use. # Find the Private key to use.
privfile="$(grep IdentityFile $HOME/.ssh/config | grep `echo $system | cut -f 1 -d '-'` | head -n 1 | cut -f 2 -d ' ')" privfile="$(grep IdentityFile $HOME/.ssh/config | grep `echo $system | cut -f 1 -d '-'` | head -n 1 | cut -f 2 -d ' ')"
if [ -z "$privfile" ]; then privfile="$HOME/.ssh/id_rsa"; fi if [ -z "$privfile" ]; then privfile="$HOME/.ssh/id_rsa"; fi
command='echo mkdir -p "$HOME/.ssh" &> /dev/null; mkdir -p "$HOME/.ssh"; chmod 0700 $HOME $HOME/.ssh; echo "'`cat $privfile.pub`'" > $HOME/.ssh/authorized_keys; cp $HOME/.ssh/authorized_keys $HOME/.ssh/id_rsa.pub; chmod 0600 $HOME/.ssh/authorized_keys; chown -R `whoami` $HOME 2>/dev/null; mv $HOME/.profile $HOME/.profile.bak 2>/dev/null; mv $HOME/.bashrc $HOME/.bashrc.bak 2>/dev/null; printf "";' command='echo mkdir -p "$HOME/.ssh" &> /dev/null; mkdir -p "$HOME/.ssh"; chmod 0700 $HOME $HOME/.ssh; echo "'`cat $privfile.pub`'" >> $HOME/.ssh/authorized_keys; cp $HOME/.ssh/authorized_keys $HOME/.ssh/id_rsa.pub; chmod 0600 $HOME/.ssh/authorized_keys; chown -R `whoami` $HOME 2>/dev/null; mv $HOME/.profile $HOME/.profile.bak 2>/dev/null; mv $HOME/.bashrc $HOME/.bashrc.bak 2>/dev/null; printf "";'
# Make sure that we have the right host signature. # Make sure that we have the right host signature.
ssh-keygen -R "$realname" ssh-keygen -R "$realname"
if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi if [ $? -ne 0 ]; then printf "FAILED\n\n"; return; fi