Linuxでユーザーに初期/基本パスワードを割り当てる方法は?

Linuxでユーザーに初期/基本パスワードを割り当てる方法は?

方法を説明するガイドが見つかりました。ユーザーパスワードの設定。私はそれを自動化し、ユーザーに次の電子メールを送信しようとしています。

userid created with password XYZ.
request to change the initial password.

上記の文書によると、Pythonを使用して暗号化されたパスワードを生成し、usermod次のコマンドに入力する必要があります。

 usermod -p "<encrypted-password>" <username>

これを行う他のより簡単な方法はありますか?これを行うために特別なユーティリティをダウンロードしたくありません。これはできるだけ一般的でなければなりません。


編集する:上のリンクに提供された方法も私には効果がないようです。

bash-3.00# python
Python 2.4.6 (#1, Dec 13 2009, 23:43:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import crypt; print crypt.crypt("<password>","<salt>")
<sOMrcxm7pCPI
>>> ^D
bash-3.00# useradd -g other -p "sOMrcxm7pCPI" -G bin,sys -m -s /usr/bin/bash mukesh2
UX: useradd: ERROR: project sOMrcxm7pCPI does not exist.  Choose another.
UX: useradd: sOMrcxm7pCPI name should be all lower case or numeric.

ベストアンサー1

chpasswdこれを行うには、次のように使用できます。

echo "username:newpassword" | chpasswd

chpasswd便利なら外部プログラムからパイプで接続できますが、echoそうすれば効果があります。

編集:シェルスクリプトでパスワードを生成して設定するには、次のようにします。

# Change username to the correct user:
USR=username
# This will generate a random, 8-character password:
PASS=`tr -dc A-Za-z0-9_ < /dev/urandom | head -c8`
# This will actually set the password:
echo "$USR:$PASS" | chpasswd

詳細については、chpasswd次を参照してください。http://linux.die.net/man/8/chpasswd

(パスワードを生成するコマンドは次のようになります。http://nixcraft.com/shell-scripting/13454-command-generate-random-password-string.html)

おすすめ記事