Pense nessa situação:
Você tem vários usuarios e vários serviços diferentes em maquinas diferentes.
Serviços de Email, Proxy, Samba mas ainda nao usa uma base centralizada como LDAP.
Bem, segue uma dica com scripts p/ automatização dessa tarefa (já pensou trocar a senha manualmente de 400 usuários ?:( , ninguém merece neh ?)
Neste caso tenho uma tabela Mysql , onde tenho os logins e senhas. A partir dela gero um arquivo csv (userstrocasenha.txt) e um script em shell p/ fazer a tarefa (troca_senha.sh) como descrito abaixo :
o texto q estiver dessa maneira é o q foi digitado :
hostmachine:~/scripts# cat userstrocasenha.txt
usertest1;xxx
usertest2;yyy
Exemplo de Autenticação com PAM
hostmachine:~/scripts# cat troca_senha.sh
#!/bin/sh
# script p/ troca de senha
# Author : Mario Cezzare - mcezzare@gmail.com
# modelo do arquivo user;senha
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
#( /usr/bin/passwd $usuario $senha)
echo -e "$senha\n$senha" | (passwd $usuario)
done
Antes de rodar o script , se quiser criar usuarios p/ testar o script :
(exemplo num Debian Linux hostmachine 2.6.26-2-686 #1 SMP Wed Nov 4 20:45:37 UTC 2009 i686 GNU/Linux )
hostmachine:~/scripts# adduser usertest1
Adding user `usertest1' ...
Adding new group `usertest1' (1007) ...
Adding new user `usertest1' (1007) with group `usertest1' ...
Creating home directory `/home/usertest1' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:x
Retype new UNIX password:x
passwd: password updated successfully
Changing the user information for usertest1
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts# adduser usertest2
Adding user `usertest2' ...
Adding new group `usertest2' (1013) ...
Adding new user `usertest2' (1013) with group `usertest2' ...
Creating home directory `/home/usertest2' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:y
Retype new UNIX password:y
passwd: password updated successfully
Changing the user information for usertest2
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts#
Vamos testar o acesso via pop3 p/ mostrar :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass x
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
hostmachine:~/scripts#
ok vamos rodar o script troca_senha.sh e ver se funciona :
hostmachine:~/scripts# sh troca_senha.sh
trocando a senha do usuario:usertest1
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
trocando a senha do usuario:usertest2
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Agora vamos testar com a nova senha :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass xxx
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
OBS: Não se esqueça de remover esses 2 usuários após os testes:
hostmachine:~/scripts# userdel -r usertest1
hostmachine:~/scripts# userdel -r usertest2
Essa é uma maneira rápida e simples de trocar as senhas quando o método de Autenticação é o PAM , e os logins e senhas ficam nos arquivos /etc/passwd e /etc/shadow , usando o programa /usr/bin/passwd (no caso dessa versão do Debian e na maioria do sistemas UNIX-LIKE)
Samba e Squid ficam p/ o próximo post
[]'s
Nenhum comentário:
Postar um comentário