全部博文(930)
分类: LINUX
2010-09-26 20:43:58
passwd Changing password for user dewang. New UNIX password: BAD PASSWORD: it is too short Retype new UNIX password: passwd: all authentication tokens updated successfully. 以非root用户修改自己的密码(注后面不能跟用户名,只有root用户才允许): passwd Changing password for user dewang. Changing password for dewang (current) UNIX password: New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully. |
echo |
echo |
#!/bin/sh # \ exec expect -f "$0" ${1+"$@"} if { $argc != 2 } { puts "Usage: $argv0 exit 1 } set password [lindex $argv 1] spawn passwd [lindex $argv 0] sleep 1 expect "assword:" send "$password\r" expect "assword:" send "$password\r" expect eof |
#!/bin/sh # \ exec expect -f "$0" ${1+"$@"} |
#!/bin/sh if [ $# -ne 2 ] ; then echo "Usage: `basename $0` exit 1 fi #echo "$2" | passwd --stdin "$1" echo "$1:$2" | chpasswd if [ $? -eq 0 ] ; then echo "change password for $1 success" else echo "change password for $1 failed" fi |
echo |
echo "newpass" | ssh -l root 10.11.103.151 passwd --stdin dewang root@10.11.103.151's password: Changing password for user dewang. passwd: all authentication tokens updated successfully. |
echo |
#!/usr/bin/expect #@brief to change user password by ssh remote machine proc usage {funcname} { puts "Usage: " puts " $funcname puts " $funcname } # check param if { $argc != 5 } { usage $argv0 exit 1 } # get param set host [lindex $argv 0] set username [lindex $argv 1] set newpasswd [lindex $argv 2] set loginname "root" if { [string compare [lindex $argv 3] "-user"] == 0 } { set loginname $username } set passwd [lindex $argv 4] puts "$host $username $newpasswd $loginname $passwd" spawn ssh -l $loginname $host expect { "*(yes/no)*" { send "yes\r"; set sshkey 1 } "*assword:*" { send "$passwd\r"; set sshkey 0 } if sshkey == 1 { expect "*password:*" send "$passwd\r" } } expect "*#" if { [string compare $loginname "root"] == 0 } { #send "echo \"$username:$newpasswd\" | chpasswd\r" send "echo \"$newpasswd\" | passwd --stdin \"$username\"\r" } else { send "passwd\r" expect { "*current*assword:" {send "$passwd\r"} "passwd: Authentication token manipulation error" {exit} } expect "New*assword:" send "$newpasswd\r" expect "Retype*assword:" send "$newpasswd\r" } expect "*#" send "exit\r" #interact 是否将交互权接过来,如果接过来,则用户这时可进行交互操作 |
chinaunix网友2010-09-29 11:34:21
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com