# ssh_trust.sh scrit for SE-HOWTO
# Copyright (c) 2008  Francesco Acquista <f.acquista@gmail.com>

# This work is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
# as published by the Free Software Foundation.
#
# This work is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this work; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

#!/bin/bash

copiaChiave ()
	{
                chiave=`cat $HOME/.ssh/id_rsa.pub`
                echo "Inserisci l'indirizzo IP oppure l'hostname cui ti vuoi collegare:"
                read target
                echo "Inserisci il nome dell'utente con il quale ti vuoi collegare:"
                read utente
                ssh -T $utente@$target "if [[ -e .ssh ]]; then echo $chiave >> .ssh/authorized_keys; else mkdir .ssh && echo $chiave >> .ssh/authorized_keys;fi"
	}

if [[ -e $HOME/.ssh/id_rsa.pub ]]
	then
		copiaChiave
	else
		echo "Procedo con la creazione della chiave di connessione."
		echo "ATTENZIONE: Non inserire alcuna password quando richiesto. Procedere premendo sempre INVIO."
		echo
		ssh-keygen
		copiaChiave
fi

# ssh_trust.sh scrit for SE-HOWTO
# Copyright (c) 2008  Francesco Acquista <f.acquista@gmail.com>

