Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 一个命令中的passwd不是';行不通_Linux_Jsch_Passwd - Fatal编程技术网

Linux 一个命令中的passwd不是';行不通

Linux 一个命令中的passwd不是';行不通,linux,jsch,passwd,Linux,Jsch,Passwd,我开发了一个工具,使用JSch(用于通过ssh与其他机器通信的java库)一次性向不同的linux机器发送一行命令 因此,我们的客户需要更改所有机器上的密码。谷歌帮助我做到了这一点: echo-e“123\n123”|密码用户名 其中“123”是新密码 命令将执行,但这始终是输出: [root@QNA-XR1 ~]# echo -e "123\n123" | passwd Changing password for root New password: Retype password: pass

我开发了一个工具,使用JSch(用于通过ssh与其他机器通信的java库)一次性向不同的linux机器发送一行命令

因此,我们的客户需要更改所有机器上的密码。谷歌帮助我做到了这一点:

echo-e“123\n123”|密码用户名
其中“123”是新密码

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

[root@QNA-XR1 ~]# echo -e "123\n123" | passwd
Changing password for root
New password:
Retype password:
passwd: password for root is unchanged
这表明命令没有成功

请注意,这是一个运行linux的小型设备。这是一个私人编译的版本,尽可能紧凑。其实我对linux了解不多

这是机器信息:

[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
以强制从终端而不是管道读取

您最好使用
crypt()
对新密码进行加密(实际上是散列),然后替换
/etc/shadow
(对于有密码的系统)或
/etc/passwd
(对于没有密码的系统)中的密码散列。这有一些操作系统依赖的缺点,但它不会进入奇怪的tty游戏


您还可以强制在ssh中分配tty—ssh可以使用或不使用tty。然后,在以明文形式发送两次密码之前,您将添加两次延迟-这种方法对操作系统的依赖性较小,但tty游戏有时可能不那么有趣。

/bin/passwd
可能会打开
/dev/tty
,以强制从终端而不是管道读取密码

您最好使用
crypt()
对新密码进行加密(实际上是散列),然后替换
/etc/shadow
(对于有密码的系统)或
/etc/passwd
(对于没有密码的系统)中的密码散列。这有一些操作系统依赖的缺点,但它不会进入奇怪的tty游戏

您还可以强制在ssh中分配tty—ssh可以使用或不使用tty。然后,在以明文形式发送密码两次之前,您将添加两次延迟-此方法对操作系统的依赖性较小,但tty游戏有时可能不太有趣。

您可以使用chpasswd(作为root用户,但不安全):

您可以使用chpasswd(作为root用户,但不安全):


您可以使用单个命令更改用户密码


echo-e“password\npassword”| sudo-S passwd testuser

您可以使用单个命令更改用户密码


echo-e“password\npassword”| sudo-S passwd testuser

用于读取密码的busybox代码非常愚蠢,并且不进行基于行的读取。您应该能够执行
(echo 123;sleep 3;echo 123)| passwd
@nos,非常感谢您的帮助。请你指点我到什么地方去看看为什么这样做?!我只是查看了密码命令的busybox源代码,它导致bb_ask_stdin函数读取密码用于读取密码的busybox代码非常愚蠢,并且不进行基于行的读取。您应该能够执行
(echo 123;sleep 3;echo 123)| passwd
@nos,非常感谢您的帮助。请你指点我到什么地方去看看为什么这样做?!我刚刚查看了password命令的busybox源代码,它导致bb_ask_stdin函数读取密码我注意到前面使用了这个命令,但是我们使用的版本没有chpasswd。非常感谢。我在前面注意到这个命令的用法,但是我们使用的版本没有chpasswd。非常感谢。我对Linux不太了解,但是说到延迟,“nos”的命令表达了你的意思吗?如果你能多解释一下你正在谈论的内容,或者建议阅读一个链接\主题,那将是非常有益的。谢谢。我对Linux不太了解,但是说到延迟,“nos”的命令表达了你的意思吗?如果你能多解释一下你正在谈论的内容,或者建议阅读一个链接\主题,那将是非常有益的。非常感谢。
# echo "user:passwd" | chpasswd