Solaris 9 安裝指南

使用結束程序檔設定系統的超級使用者密碼

安裝了 Solaris 軟體之後,系統會重新啟動。 在開機程序完成前,系統會要求您輸入超級使用者密碼。 除非有人鍵入密碼,否則系統無法完成開機。

名為 set_root_pw 的結束程序檔儲存在 auto_install_sample 目錄中。 結束程序檔顯示不詢問使用者,而自動設定超級使用者密碼的方法。 set_root_pw 顯示於範例 24–5中。


範例 24–5 使用結束程序檔設定系統的超級使用者密碼

	 #!/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 file1
 cp /a/etc/shadow /a/etc/shadow.orig2
 
	 mv /a/etc/shadow /a/etc/shadow.orig
 	nawk -F: '{
         if ( $1 == "root" )3
           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.orig4
 # set the flag so sysidroot won't prompt for the root password
 sed -e 's/0 # root/1 # root/' ${SI_SYS_STATE}> /tmp/state.$$5
  mv /tmp/state.$$ ${SI_SYS_STATE}
  1. 將變數 PASSWD 設為加密的超級使用者密碼,該密碼是從系統的 /etc/shadow 檔案中的現存項目所取得。

  2. 建立一個 /a/etc/shadow 暫時輸入檔案。

  3. 使用 $PASSWD 作為密碼欄位,對新安裝的系統變更 /etc/shadow 檔案中的根登錄。

  4. 移除 /a/etc/shadow 暫存檔。

  5. 在狀態檔中將項目由 0 變更為 1,這樣系統就不會要求使用者輸入超級使用者密碼。狀態檔是藉由使用變數 SI_SYS_STATE 所存取,該變數的值是 /a/etc/.sysIDtool.state 。 若要避免因值改變而發生的程序檔問題,請一律使用 $SI_SYS_STATE 來參照此檔案。 此處所顯示的 sed 指令在 01 之後包含一個跳格字元。



註解 –

如果您使用一個結束程序檔來設定系統的超級使用者密碼,使用者可能會嘗試在結束程序檔的加密密碼中尋找超級使用者密碼。 確保您可以防止其他使用者嘗試決定超級使用者密碼。