-
Notifications
You must be signed in to change notification settings - Fork 2
/
redefinirusuario
32 lines (32 loc) · 1.33 KB
/
redefinirusuario
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
if [ $(id -u) -eq 0 ]
then
echo -e "\033[1;32mNome do novo usuario:\033[0;37m"; read -p " " name
echo -e "\033[1;32mSenha para o usuario $name:\033[0;37m"; read -p " " pass
echo -e "\033[1;32mQuantos dias usuario $name deve durar:\033[0;37m"; read -p " " daysrnf
echo -e "\033[1;32mLimite de logins simultaneos:\033[0;37m"; read -p " " limiteuser
echo -e "\033[0m"
if cat /etc/passwd |grep $name: |grep -vi [a-z]$name |grep -v [0-9]$name > /dev/null
then
echo -e "\033[1;31mUsuario $name ja existe\033[0m"
else
valid=$(date '+%C%y-%m-%d' -d " +$daysrnf days")
datexp=$(date "+%d/%m/%Y" -d "+ $daysrnf days")
useradd -M -s /bin/false $name -e $valid
( echo "$pass";echo "$pass" ) | passwd $name 2> /dev/null
limite $name $limiteuser
echo -e "\033[1;36mUsuario: \033[0m$name"
echo -e "\033[1;36mSenha: \033[0m$pass"
echo -e "\033[1;36mExpira:\033[0m $datexp"
echo "$pass" > /etc/vpsconf/senha/$name
fi
else
if echo $(id) |grep sudo > /dev/null
then
echo "Seu usuario esta no grupo sudo"
echo -e "Para virar root execute \033[1;31msudo su\033[0m"
echo -e "Ou execute o criarusuario como sudo. \033[1;31msudo criarusuario\033[0m"
else
echo -e "Vc nao esta como usuario root, nem com seus direitos (sudo)\nPara virar root execute \033[1;31msu\033[0m e digite sua senha root"
fi
fi