Pages

Tuesday, October 26, 2010

உபுண்டுவில் பயனாளரின் கடவுச்சொல் மாற்ற ஒரு script

உபுண்டுவில் கடவுச்சொல் மாற்ற இந்த script உதவுகிறது. முதலில் கீழ்கண்ட வரிகளை காப்பி செய்து ஒரு text கோப்பினுள் இடவும். பின்னர் அதற்கு ஒரு பெயர் கொடுத்து சேமிக்கவும். இந்த script இயங்க முதலில் expect என்னும் நிரலை நிறுவிக்கொள்ளவேண்டும். எனவே டெர்மினலில்

sudo apt-get install expect என்று தட்டச்சு செய்து நிறுவிக்கொள்ளவேண்டும்.

#!/usr/bin/expect -f
# Password change shell script, tested on Linux and FreeBSD
# ----------------------------------
# It need expect tool. If you are using Linux use following command
# to install expect
# apt-get install expect
# display usage
if {$argc!=2} {
send_user "usage: $argv0 username password \n"
exit
}
# script must be run by root user
set whoami [exec id -u]
if {$whoami!=0} {
send_user "You must be a root user to run this script\n"
exit
}
#
set timeout -1
match_max 100000
# stopre password
set password [lindex $argv 1]
# username
set user [lindex $argv 0]
# opem shell
spawn $env(SHELL)
# send passwd command
send -- "passwd $user\r"
expect "assword:"
send "$password\r"
expect "assword:"
send "$password\r"
send "\r"
expect eof

நான் இதற்கு chpass.sh என்று பெயர் கொடுத்து மேசைமீது வைத்திருக்கிறேன். எனவே டெர்மினலில்

arulmozhi@arulmozhi-945GZM-S2:~$ cd Desktop

arulmozhi@arulmozhi-945GZM-S2:~/Desktop$ sudo chmod +x chpass.sh
arulmozhi@arulmozhi-945GZM-S2:~/Desktop$ ./chpass.sh
usage: ./chpass.sh username password

arulmozhi@arulmozhi-945GZM-S2:~/Desktop$ ./chpass.sh username password
You must be a root user to run this script
arulmozhi@arulmozhi-945GZM-S2:~/Desktop$ sudo ./chpass.sh username password
spawn /bin/bash
passwd arulmozhi
root@arulmozhi-945GZM-S2:~/Desktop# passwd arulmozhi
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@arulmozhi-945GZM-S2:~/Desktop#
root@arulmozhi-945GZM-S2:~/Desktop#

இந்த script ஐ உபயோகிக்க

sudo ./chpass.sh username password என்று கட்டளையிடவேண்டும்.


இப்போது கடவுச்சொல் மாற்றப்பட்டு இருக்கும்.

No comments: