一个命令中的passwd不起作用 [英] passwd in one command isn't working

查看:393
本文介绍了一个命令中的passwd不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一种工具,可以使用JSch(用于通过ssh与其他计算机进行通信的Java库)将单行命令发送到不同的linux计算机

I developed a tool to send one-line commands to different linux machines in one shot using JSch (A java library used to communicating with other machines over ssh)

因此,我们的客户需要在所有计算机上更改密码. Google帮助我达到了这一点:

So our client needs to change the password on ALL machines. Google helped me reach this point:

echo -e "123\n123" | passwd username 其中"123"是新密码.

echo -e "123\n123" | passwd username Where '123' is the new password.

该命令已执行,但这始终是输出:

The command executes but this is ALWAYS the output:

[root@QNA-XR1 ~]# echo -e "123\n123" | passwd
Changing password for root
New password:
Retype password:
passwd: password for root is unchanged

这表示命令没有成功.

请注意,这是一台运行Linux的小型设备.这是一个尽可能紧凑的私人编译版本.我实际上对Linux不太了解!

Please note that this is an small device with linux running on it. It's a privately compiled version to be as compact as possible. I don't know much about linux actually !

这是机器信息:

[root@QNA-XR1 ~]# uname -a
Linux QNA-XR1 2.6.22-XR100-v1.1.7 #1 Tue Aug 19 22:55:50 EDT 2008 ppc unknown

密码帮助:

[root@QNA-XR1 ~]# 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

回声帮助

[root@QNA-XR1 ~]# 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.

非常感谢您的帮助.

推荐答案

/bin/passwd可能正在打开/dev/tty,以强制从终端而不是管道进行读取.

/bin/passwd may be opening /dev/tty to force reading from a terminal instead of a pipe.

最好使用crypt()加密(散列)新密码,然后替换/etc/shadow(对于具有密码的系统)或/etc/passwd(对于没有密码的系统)中的密码哈希).这样做的缺点是与操作系统有关,但它不会进入奇怪的tty游戏.

You may be better off encrypting (hashing, really) your new password using crypt(), and then replacing the password hash in /etc/shadow (for systems that have it) or /etc/passwd (for systems that don't). This has the disadvantage of being somewhat OS-dependent, but it doesn't get into weird tty games.

您也许还可以在ssh中强制分配tty-ssh既可以运行也可以不运行.然后,您将在两次以明文形式发送密码之前增加一些延迟-这种方法与操作系统的依赖程度较小,但是tty游戏有时会变得不那么有趣.

You might also be able to force allocation of a tty in ssh - ssh can operate both with or without one. Then you would add a couple of delays before sending the password in plaintext twice - this method is less OS-dependent, but tty games can be less than fun sometimes.

这篇关于一个命令中的passwd不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆