User:Rkorgmaa: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Rkorgmaa (talk | contribs)
No edit summary
Rkorgmaa (talk | contribs)
No edit summary
Line 69: Line 69:




Luua skript, mis seadistab võtmete baasil autentimise ssh abil.


<source lang="bash">
<source lang="bash">

Revision as of 12:33, 31 May 2011

Kood on võetud Toomas Rohumetsa wikist. https://wiki.itcollege.ee/index.php/User:Trohumet

Antud skript suudab ka teistele võrguliidestele aliaseid külge pookida.

#!/bin/bash
#Autor: Toomas Rohumets A21
#Skript, mis loob Ubuntu serverile IP aliase
#Versioon 0.5
 
#Õiguste kontroll
if [ $UID -ne 0 ]; then
echo "Käivita skript $(basename $0) juurkasutaja õigustega"
exit 1
 
fi
 
if [ -z $2 ];
then
	iface="eth0"
else
	iface=$2
fi


#Kontroll kas IP on parameetrina antud 
if [ $# -lt 1 ]; then
        echo "Skripti kasutamine $(basename $0) <ip-address> <interface>(optional)"
        exit 1
fi
 
IP=$1
 
#Aliaste kontroll
x=($(ifconfig | grep $iface: | cut -d":" -f2 | cut -d" " -f1))
 
if [ ! -n "$x" ]; then
	nr=0
else
	nr=${#x[@]}
fi
 
#Ping, kontrollimaks kas IP on kasutuses
ping -c 3 $IP
 
if [ $? -eq 0 ]; then
        echo "IP on olemas"
        exit 1
else
        echo "IP on vaba"
#IP ja võrgumaski sisestus /etc/network/interfaces faili
        cat >> /etc/network/interfaces <<EOF
auto $iface:$nr
iface $iface:$nr inet static
    address $IP
    netmask $(ifconfig $iface | grep Mask | cut -d ':' -f 4)
EOF
#Võrgule restart
/etc/init.d/networking stop
/etc/init.d/networking start 
 
#Tulemus
echo "Loodi alias IPga $IP"
fi


Luua skript, mis seadistab võtmete baasil autentimise ssh abil.

#!/bin/bash
if [ "$1" = "" ]; then
 	echo "$(basename $0) kasutajanimi@host"
	exit 1
fi
echo "Lubame  $(whoami)@$(hostname) võtmete abil autentimise hosti $@"
if [ -f "$HOME/.ssh/id_dsa" ]; then
	echo "DSA on juba loodud, jätkame"
else
	ssh-keygen -t dsa -N "" -f $HOME/.ssh/id_dsa
fi
cat $HOME/.ssh/id_dsa.pub | ssh $@ "mkdir -p .ssh && cat >> .ssh/authorized_keys2"