linux - 一个命令中的密码不起作用

标签 linux jsch passwd

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

所以我们的客户需要更改所有机器上的密码。 Google 帮助我达到了这一点:

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

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

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

表示命令没有成功。

请注意,这是一个运行 linux 的小型设备。这是一个私有(private)编译的版本,尽可能紧凑。其实我对 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.

非常感谢您的帮助。

最佳答案

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

# echo "user:passwd" | chpasswd

关于linux - 一个命令中的密码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11402274/

相关文章:

linux - 集群中的 nohup 多个命令

c - 如何更改此代码以写入标准输出?

java - 将 Jsch 0.1.42 升级到 0.1.54 会产生与远程服务器的连接超时

linux - linux 密码命令

linux - 在 docker 中使用 passwd 出现错误 "passwords do not match"

android - ADT - libstdc++.so.6 : cannot open shared object file

c++ - 检查输入和 sleep boost 线程

java - 当使用 JSch 通过 Java 执行时,某些 Unix 命令会失败并返回 "... not found"

java - 将私钥从 PuTTY 格式转换为 OpenSSH 格式后,是否需要向服务器添加新的公钥?

c++ - 使用 C++ 中的 try 和 catch 方法创建一个函数以获取用户名