Solaris ソフトウェアがシステムにインストールされると、そのシステムはリブートします。ブートプロセス終了前に、システムはルートパスワードを入力するように求めてきます。パスワードを入力するまで、システムはブート処理を終了できません。
set_root_pw という finish スクリプトは、auto_install_sample ディレクトリに保存されます。この finish スクリプトは、プロンプトを表示することなく root パスワードを自動的に設定する方法を示します。例 27–5 に set_root_pw を示します。
finish スクリプトを使用してシステムのルートパスワードを設定した場合は、 finish スクリプト内の暗号化されたパスワードからルートパスワードを解読されないように対策を講じてください。
#!/bin/sh
#
# @(#)set_root_pw 1.4 93/12/23 SMI
#
# This is an example Bourne shell script to be run after installation.
# It sets the system's root password to the entry defined in PASSWD.
# The encrypted password is obtained from an existing root password entry
# in /etc/shadow from an installed machine.
echo "setting password for root"
# set the root password
PASSWD=dKO5IBkSF42lw
#create a temporary input file
cp /a/etc/shadow /a/etc/shadow.orig
mv /a/etc/shadow /a/etc/shadow.orig
nawk -F: '{
if ( $1 == "root" )
printf"%s:%s:%s:%s:%s:%s:%s:%s:%s\n",$1,passwd,$3,$4,$5,$6,$7,$8,$9
else
printf"%s:%s:%s:%s:%s:%s:%s:%s:%s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9
}' passwd="$PASSWD" /a/etc/shadow.orig > /a/etc/shadow
#remove the temporary file
rm -f /a/etc/shadow.orig
# set the flag so sysidroot won't prompt for the root password
sed -e 's/0 # root/1 # root/' ${SI_SYS_STATE} > /tmp/state.$$
mv /tmp/state.$$ ${SI_SYS_STATE}
|
以下に、この例のいくつかのコマンドの説明を示します。
次のコマンドは、PASSWD 変数に、システムの /etc/shadow ファイルの既存のエントリから取得した暗号化されたルートパスワードを設定します。
#create a temporary input file |
次のコマンドは、/a/etc/shadow の一時入力ファイルを作成します。
cp /a/etc/shadow /a/etc/shadow.orig |
次のコマンドは、$PASSWD をパスワードフィールドとして使用して、新しくインストールしたシステム用の /etc/shadow ファイルにあるルートエントリを変更します。
if ( $1 == "root" ) |
次のコマンドは、一時的な /a/etc/shadow ファイルを削除します。
rm -f /a/etc/shadow.orig |
次のコマンドは、状態ファイルのエントリを 0 から 1 へ変更します。これによりユーザーはルートパスワードの入力を求められません。この状態ファイルには、SI_SYS_STATE 変数 (現在の値は /a/etc/.sysIDtool.state) を使用してアクセスします。この値の変更によってスクリプトで問題が発生することを防ぐには、必ず $SI_SYS_STATE を使用してこのファイルを参照してください。ここに示されている sed コマンドでは、0 と 1 の後にタブ文字が入っています。
sed -e 's/0 # root/1 # root/' ${SI_SYS_STATE} > /tmp/state.$$
|