16 lines
849 B
Bash
Executable File
16 lines
849 B
Bash
Executable File
#!/bin/bash
|
|
|
|
searchterm="$1"
|
|
if [ -z "$searchterm" ]; then searchterm="'*'"; fi
|
|
for system in `egrep '^Host ' $HOME/.ssh/config | cut -f 2 -d ' ' | egrep $searchterm`; do
|
|
printf "$system ... "
|
|
privfile="$(grep IdentityFile $HOME/.ssh/config | grep `echo $system | cut -f 1 -d '-'` | head -n 1 | cut -f 2 -d ' ')"
|
|
command='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; mv $HOME/.profile $HOME/.profile.bak; mv $HOME/.bashrc $HOME/.bashrc.bak'
|
|
ssh $system bash -c "$command"
|
|
if [ $? -ne 0 ]; then printf "FAILED\n"; continue; fi
|
|
scp $privfile $system:.ssh/id_rsa
|
|
scp $HOME/.bashrc $system:.bashrc
|
|
scp $HOME/.profile $system:.profile
|
|
printf "DONE\n"
|
|
done
|