如何取得MAC OS X root 身分?

三個啟動超級用戶模式(root user)的方法

root user(又名超級用戶 - superuser)是一個非常有權力的 Unix 賬戶,root 的賬戶能在整個系統裡任何部份進行任何「活動」,包括:拷貝檔案、移動移除檔案、執行程式等。所以,通常 root 的賬戶都只會指派給高級專業的用戶使用。因此,蘋果選擇把root user 隱藏在 Mac OS X 裡。

但我們仍然可以透過以下幾種方法把 root 的賬戶啟動:

方法一:
啟動 Mac OS X 的安裝光碟,在安裝菜單裡選擇「Password Reset」項目,便能更改閣下的密碼和啟動超級用戶模式。(把這工具拷貝到硬碟中是不能啟動的,一定要從光碟啟動才有效。)

方法二:
啟動在 Mac OS X 裡的 Terminal,輸入以下命令:
sudo passwd root
系統會即時要求閣下輸入 root user 的新密碼,然後再輸入一次,以確保密碼正確。

方法三:
啟動 NetInfo Manager 應用程式(在「Applications/Utilities」的文件夾中),再依照以下步驟:
1. 從第二個列表裡選擇「users」目錄,再選「root」 (見圖二)
2. 點按窗口底部的「鎖型」icon,然後以閣下在安裝過程中提供的用戶名稱和密碼註冊。
3. 從窗口下半部份的列表中選擇 * 號一欄,再輸入 root user 已加密的新密碼。

可在 Terminal 裡輸入以下的「htpasswd」命令來產生加密的新密碼:
[localhost:~] currentuser% htpasswd -nb anylogin yourpassword
[return]
[localhost:~] currentuser% anylogin : pu9fQgdzVHRB2
pu9fQgdzVHRB2 就是已加密的新密碼


4. 點按窗口底部的「鎖型」icon,然後儲存更改和離開 NetInfo Manager。

現在可以在 Terminal 裡試試 root user 的新密碼!

另一個做法是用系統管理員的身分登入後,在Termianl打sudo su,這時回答你現在身分的密碼就可以了。你就會看到提示符號原本的帳號變成了root了,在摸Mac之前接觸過Linux的確有點幫助呢!!!

順帶一提,
如果你要在Terminal下shutdown指令,可以這樣下指令:
# /sbin/shutdown -h now
reboot :
#/sbin/reboot



Enabling the root Account on Mac OS X

The "superuser" (i.e. root) account, which controls everything in Unix, is turned off by default in most Mac OS X installations. These instructions tell you how to enable the Unix root account on Mac OS X.

The default Mac OS X installation (at least here at Vassar) has the Unix root account disabled. This is probably a good thing, since the casual user does not need all the powers granted to the root account. But there are times when it is useful to become root to fix something or to debug a problem. Follow these instructions to enable the root account and to make it easy for the root user to get a shell prompt.

Making changes like this to the system requires some administrative privileges. You will need to know the password for the "Admin" account.

This method will also work to remove a root password that you have forgotten (as long as you still know the "Admin" password or are a user with administrative privleges).


1. First, you can verify that the root user account is indeed locked (or you can skip directly to step 2 below). One way to do this is to get a shell prompt by running the Terminal application, found at Macintosh HD -> Applications -> Utilities -> Terminal

At the command prompt type this command:

% nidump passwd .

(Don't type the "%" - that represents the Unix command prompt. And don't forget the "dot" at the end, which indicates that the "password" map to be dumped to the screen is the one on this machine, not the password map from a remote server.) You should see a line like this:

root:*:0:0:System Administrator:/var/root:/bin/tcsh

The "*" is where the encrypted password for the user would normally go. If the root account has a "*" then it is not possible for a user to log in or to set their userid to root.

2. To remove the "*" (or any old password) you need to run the NetInfo Manager application, which is also in the Utilities folder: Macintosh HD -> Applications -> Utilities -> NetInfo Manager

3. With "/" in the left column select the "users" map in the second column and click on the "root" user.

4. Click on the lock icon at the bottom of the window marked "Click to make changes". Enter the administrative password as prompted. You are now free to make changes to the users map.

5. Find the "passwd" property and double click on the value field to alter it (it should contain just the "*", or possibly an old encrypted password). Delte the "*" and make sure there are no spaces left in the value field.

You cannot simply enter a new password here, because Unix stores an encrypted version of the password in the user database (passwd map). We'll need to use the passwd command (step 7 below) to enter a new password.

6. Pull down the "Domain" menu from the top bar and select "Save Changes". Confirm that you really want to make the change.

7. Get a shell prompt (from the Terminal application, as described in step 1 above). Enter the command:

% su root

(Don't enter the %, that represents the Unix command prompt.) When prompted for the password, just hit "return". Then add a password with the `passwd root` command, like so:

# passwd root
Changing password for root
New password:
Verify password:

(Don't enter the #, that is the root command prompt on Unix.) The password you type won't be printed on the screen, which is why you are asked to type it twice for verification.

8. Log out and log in as the root user to verify that it worked. If the login screen shows a list of users it won't show the root user so you will have to select "Other".

9. It's very useful for the root user to have the Terminal application always in the Dock. Here is how to do that:

* First, start up the Terminal application (Macintosh HD -> Applications -> Utilities -> Terminal)

* Hold down the "control" key as you click on the icon of the Terminal application in the Dock. A menu will appear. Select the item "Keep In Dock".

Addendum: if you log on to the machine using the Admin account then it is also possible to enable the root account more quickly via a pull-down menu, as follows:

1. Start the NetInfo Manager application (if you don't have this in the dock for the Admin account you should probably put it there, it's very useful for system administration).

2. From the top menu bar pull down the "Security" item and select "Enable root user".
arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()