GUIアプリケーションを介したユーザーパスワードの変更

GUIアプリケーションを介したユーザーパスワードの変更

私はLinuxでユーザーとグループを管理するためのGUIアプリケーションを作成しています!

新しいユーザーの作成は完了しましたが、新しく作成されたユーザーに新しいパスワードを提供する部分ではまだ輻輳状態です。私のアプリケーションが行うことは、GUIを介して必要な入力(ユーザー名、グループリスト、パスワード)を取得し、この情報をパラメータとして渡すスクリプトを実行することだけです。ユーザーアカウントxyzがあるとしましょう。そのアカウントのパスワードを変更するには、次のコマンドを実行します。

passwd xyz

新しいパスワードの入力を求められます。これで、必要なすべての情報がコマンドラインに渡されるので、スクリプトを使用して新しいアカウントを作成できます。

useradd -m -G users -g "groups" -s /bin/bash "UserName"

Qtアプリケーションを介してスクリプトを実行してユーザーを作成できますが、他の行はpasswd cmd入力を要求します。人々はこの問題をどのように扱いますか?

答え1

私の考えに正解は次のとおりです。コマンドラインツールを使用せずにライブラリ呼び出しを使用してください。。これにより、エラーをより適切に処理し、コマンドラインからパスワードを渡すリスクを回避できます。

使用できるライブラリの1つは次のとおりです。図書館利用者、比較的簡単で、CとPythonバインディングがあります。

答え2

ルートとして、次のようにスクリプトを使用して体系的にユーザーのパスワードを設定できます。

$ echo -n "$passwd" | passwd "$uname" --stdin

パスワード生成

私はコマンドラインツールを使用するのが好きです。pwgenパスワードを生成します。

$ passwd="`pwgen -1cny | sed 's/[\$\!]/%/g'`"

$ pwgen --help
Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]

Options supported by pwgen:
  -c or --capitalize
    Include at least one capital letter in the password
  -A or --no-capitalize
    Don't include capital letters in the password
  -n or --numerals
    Include at least one number in the password
  -0 or --no-numerals
    Don't include numbers in the password
  -y or --symbols
    Include at least one special symbol in the password
  -s or --secure
    Generate completely random passwords
  -B or --ambiguous
    Don't include ambiguous characters in the password
  -h or --help
    Print a help message
  -H or --sha1=path/to/file[#seed]
    Use sha1 hash of given file as a (not so) random generator
  -C
    Print the generated passwords in columns
  -1
    Don't print the generated passwords in columns
  -v or --no-vowels
    Do not use any vowels so as to avoid accidental nasty words

しかし、それは不安ではありませんか?

習慣。パスワードはSTDINを介して渡されるため、passwd誰かがプロセスをスヌーピングしてもユーザーがルートプロセスを表示できない場合でも、psパスワードの配信は隔離されます。passwd

はい

端末からrootとしてこのコマンドを実行するとします。

$ ( sleep 10; echo "supersecret" | passwd "samtest" --stdin ) &
[1] 13989

その後、ps別の端末で実行します。

$ ps -AOcmd | grep pass
14046 passwd samtest --stdin      R pts/11   00:00:00 passwd samtest --stdin

最初の端末でパスワードを変更した後:

[root@greeneggs ~]# Changing password for user samtest.
passwd: all authentication tokens updated successfully.

passwdのエコーはどうですか?

それでもパスワードは公開されません。これを証明するための別のテストがあります。まず、セカンダリ端末でこのコマンドを実行します。これにより出力が収集されますps

$ while [ 1 ]; do ps -eaf2>&1 | grep -E "echo|pass";done | tee ps.txt

その後、パスワード設定コマンドを実行します。

$ echo "supersecret" | passwd "samtest" --stdin &
[1] 20055
$ Changing password for user samtest.
passwd: all authentication tokens updated successfully.

[1]+  Done                    echo "supersecret" | passwd "samtest" --stdin

内容を確認してみると、ps.txtパスワードが流出していないことがわかりました。

$ grep supersecret ps.txt
$

ps使用するコマンドを変更してps -eafも漏れません。

答え3

passwd --help私のボックスは、標準入力に新しいパスワードを提供するrootために実行できることを示しています。--stdin

答え4

chpasswdコマンドは、コマンドラインからユーザー名とパスワードのペアのリストを読み取り、既存のユーザーセットを更新します。各行の形式は次のとおりです。

user_name:password

このコマンドは、複数のアカウントが同時に作成される大規模システム環境で使用するためのものです。このコマンドの追加オプションについては、次のように入力してください。

man chpasswd

関連情報