meta data for this page
  •  

SSH kulcs terítő szkript

lnx_copy_ssh_id.exp
#!/usr/bin/expect -f
 
set host [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh-copy-id -i /home/$user/.ssh/id_ecdsa.pub $host
 
expect {
    "continue" { send "yes\n"; exp_continue }
    "assword:" { send "$password\n"; }
    "added: 1" { exit 0 }
    "added: 0" { exit 1 }
}
lnx_copy_ssh_id.sh
#!/bin/bash
echo -n "Add meg a jelszavad a(z) $USER felhasznalohoz: "
read -s PASSWORD
echo
INPUT_FILE=$1
 
 
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
whi=$'\e[1;37m'
inv=$'\e[7;37m'
gry=$'\e[1;90m'
end=$'\e[0m'
nor=$'\e[0m'
 
 
grep -v '^#' $INPUT_FILE | while read HOST; do
    printf "Kulcs masolasa: ${USER}@${HOST}..."
    expect ./lnx_copy_ssh_id.exp $HOST $USER $PASSWORD > /dev/null
    if [[ $? -eq 0 ]]; then
        printf "${grn}OK${nor}"
    else
        printf "${red}HIBA${nor}"
    fi
    printf ", Teszt kapcsolodas..."
    HOST2=$(ssh -n -o ConnectTimeout=5 $HOST hostname)
    if [[ $? -eq 0 && "${HOST%%\.*}" == "${HOST2%%\.*}" ]]; then
        echo "${grn}OK${nor}"
    else
        [[ "${HOST%%\.*}" == "${HOST2%%\.*}" ]] && echo echo "${red}HIBA - nem sikerult kapcsolodni{nor}" || echo "${red}HIBA - $HOST <> $HOST2${nor}"
    fi
done