0

JSch (ssh を介して他のマシンと通信するために使用される Java ライブラリ) を使用して、1行のコマンドをさまざまな Linux マシンに 1 回で送信するツールを開発しました。

したがって、クライアントはすべてのマシンでパスワードを変更する必要があります。Googleは私がこの点に到達するのを助けました:

echo -e "123\n123" | passwd username 「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.

助けてくれてありがとう。

4

3 に答える 3

3

chpasswdを使用できます(ルートとして使用できますが、安全ではありません)。

# echo "user:passwd" | chpasswd
于 2012-07-09T20:14:41.490 に答える
2

/bin/passwd/dev/ttyパイプではなく端末からの読み取りを強制するために開いている可能性があります。

を使用して新しいパスワードを暗号化 (実際にはハッシュ) し、パスワード ハッシュを(それがあるシステムの場合) または(ないシステムの場合)crypt()に置き換える方がよい場合があります。これには、多少 OS に依存するという欠点がありますが、奇妙な tty ゲームにはなりません。/etc/shadow/etc/passwd

ssh で tty の割り当てを強制することもできます。ssh は tty の有無にかかわらず動作します。次に、パスワードをプレーンテキストで 2 回送信する前に、2、3 の遅延を追加します。この方法は OS にあまり依存しませんが、tty ゲームは面白くない場合があります。

于 2012-07-09T20:11:01.117 に答える
1

単一のコマンドを使用して、ユーザー パスワードを変更できます。

echo -e "password\npassword" | sudo -S passwd testuser

于 2018-03-16T10:53:11.597 に答える