我开发使用JSchpasswd文件中的一个命令不工作
左右(用于与通过ssh其他机器进行通信的Java库)发送一次性单行命令在不同的Linux机器的工具我们的客户需要更改所有机器上的密码。谷歌帮我达到了这一点:
echo -e "123\n123" | passwd username
其中'123'是新的密码。
该命令执行,但是这始终是输出:
[[email protected] ~]# echo -e "123\n123" | passwd
Changing password for root
New password:
Retype password:
passwd: password for root is unchanged
表明该命令没有成功。
请注意,这是一个运行linux的小设备。这是一个私人编译的版本,尽可能紧凑。实际上我对Linux不是很了解!
这是机器的信息:
[[email protected] ~]# uname -a
Linux QNA-XR1 2.6.22-XR100-v1.1.7 #1 Tue Aug 19 22:55:50 EDT 2008 ppc unknown
passwd的帮助:
[[email protected] ~]# passwd --help
BusyBox v1.7.3 (2008-01-09 00:06:30 EST) multi-call binary
Usage: passwd [OPTION] [name]
Change a user password. If no name is specified,
changes the password for the current user.
Options:
-a Define which algorithm shall be used for the password
(choices: des, md5)
-d Delete the password for the specified user account
-l Locks (disables) the specified user account
-u Unlocks (re-enables) the specified user account
回声帮助
[[email protected] ~]# help echo
echo: echo [-neE] [arg ...]
Output the ARGs. If -n is specified, the trailing newline is
suppressed. If the -e option is given, interpretation of the
following backslash-escaped characters is turned on:
\a alert (bell)
\b backspace
\c suppress trailing newline
\E escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\num the character whose ASCII code is NUM (octal).
You can explicitly turn off the interpretation of the above characters
with the -E option.
非常感谢提前对您有所帮助。
读取密码busybox的代码是非常愚蠢的,并没有做基于行的读数。你应该可以做'(echo 123; sleep 3; echo 123)| passwd' – nos 2012-07-09 20:19:43
@nos,非常感谢你的诀窍。你能否引导我到某个地方去阅读它为什么这样工作? – 2012-07-09 20:31:49
我只是看了一下busybox的密码命令的源代码,这导致了bb_ask_stdin函数读取密码 – nos 2012-07-09 20:32:18