批量增加用户,设置密码,用shell来实现 要先确认你的passwd支持“–stdin”参数 参考这里 <http://stackoverflow.com/questions/714915/using-the-passwd-command-from- within-a-shell-script>

from “man 1 passwd”: --stdin This option is used to indicate that passwd should read the new password from standard input, which can be a pipe. So in your case adduser “$1” echo “$2” | passwd “$1” –stdin [Update] a few issues were brought up in the comments: Your passwd command may not have a –stdin option: use the chpasswd utility instead, as suggested by ashawley. If you use a shell other than bash, “echo” might not be a builtin command, and the shell will call /bin/echo. This is insecure because the password will show up in the process table and can be seen with tools like ps. In this case, you should use another scripting language. Here is an example in Perl: #!/usr/bin/perl -w open my $pipe, ‘|chpasswd’ or die “can’t open pipe: $!”; print {$pipe} “$username:$password”; close $pipe

更严谨的考虑:

echo $mypassword | passwd –stdin # Eternal Sin. echo “$mypassword” | passwd –stdin # Eternal Sin, but at least you remembered to quote your PE. passwd –stdin «< “$mypassword” # A little less insecure, still pretty insecure, though. passwd –stdin < “passwordfile” # With a password file that was created with a secure umask(1), a little bit secure.