#!/bin/bash ######### Skrypt zarzadzajacy userami ########### #############adrian@net-hosting.pl############### #TODO: Duplikowanie i usuwanie nazw z AllowUsers# # sprwadzamy czy root if [ $UID != 0 ]; then echo "Nie masz uprawnien" exit 0 fi echo -n "Nazwa usera: " read user #zmienne passwd=/etc/passwd sshd=/etc/ssh/sshd_config sprawdz="grep $user" temp=/tmp/autoryzacja restart='/etc/init.d/ssh restart' if [[ $(grep 'PermitRootLogin no' $sshd) == "" ]] then sed -e 's/^PermitRootLogin.*/PermitRootLogin no/' $sshd > $sshd.tmp && /bin/mv $sshd.tmp $sshd fi if [[ $(grep 'AllowUsers' $sshd) == "" ]] then echo "AllowUsers" >> $sshd fi if [[ $($sprawdz $passwd) != "" ]] then echo "User istnieje w systemie"; echo -n "Usunac? [y/n]" read del if [ $del == y ] then deluser --remove-all-files --remove-home $user exit 0 fi echo -n "Czy chcesz zmienic haslo? [y/n]" read odp if [ $odp == y ] then passwd $user fi if [[ $($sprawdz $sshd) != "" ]] then echo "User juz jest zautoryzowany" exit 0 else grep "AllowUsers" $sshd > $temp && echo -n `cat $temp` $user > $temp sed -e "s/^AllowUsers.*/$(cat $temp)/" $sshd > $sshd.tmp && /bin/mv $sshd.tmp $sshd rm $temp $restart exit 0 fi else echo "User nie istnieje w systemie" useradd -m $user passwd $user grep "AllowUsers" $sshd > $temp && echo -n `cat $temp` $user > $temp sed -e "s/^AllowUsers.*/$(cat $temp)/" $sshd > $sshd.tmp && /bin/mv $sshd.tmp $sshd rm $temp $restart fi exit 0