Solaris 軟體在系統上安裝完畢後,系統會重新啟動。在啟動程序完成前,系統會提示您輸入 Root 密碼。除非鍵入密碼,否則系統無法完成啟動。
名為 set_root_pw 的結束程序檔會儲存在 auto_install_sample 目錄中。結束程序檔顯示如何在不進行提示的情況下,自動設定 Root 密碼。範例 7–6 中會顯示 set_root_pw。
如果使用結束程序檔設定系統的 Root 密碼,使用者可能會企圖在結束程序檔中從加密的密碼找出 Root 密碼。請確保您可以防止使用者嘗試確定 Root 密碼。
#!/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 設定為加密的 Root 密碼,該密碼取自系統的 /etc/shadow 檔案中現有的項目。
#create a temporary input file |
以下指令建立 /a/etc/shadow 的臨時輸入檔案。
cp /a/etc/shadow /a/etc/shadow.orig |
以下指令使用 $PASSWD 做為密碼欄位,對新安裝的系統變更 /etc/shadow 檔案中的 root 項目。
if ( $1 == "root" ) |
以下指令移除臨時 /a/etc/shadow 檔案。
rm -f /a/etc/shadow.orig |
以下指令在狀態檔中將項目由 0 變更為 1,這樣系統就不會提示使用者輸入 Root 密碼。狀態檔是使用變數 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.$$ |