Ubuntu 修改用戶UID爲0後無法識別root和用戶賬號解決辦法

看鳥哥私房菜時講到多個用戶可以有相同的UID,且如果將用戶UID改成0後則用戶擁有和root一樣的權限,於是我試驗了一下,修改/etc/passwd文件,將我登錄的用戶yhl的UID改成0(和root的UID相同),這一改就出問題了,當我在終端退出登錄再重新用root/yhl賬號登錄的時候系統提示識別不了用戶名,而且我的yhl賬號也並沒有修改/etc/passwd的權限,重啓Ubuntu時桌面更是連登錄賬號都不顯示了。

     上網查了下解決辦法,如下

ask ubuntu的方案(From Thomas Ward)
Without booting to a LiveUSB or LiveCD/DVD, we can actually borrow some of the steps from this answer on resetting a lost password to get to a recovery console, and then make changes to the system and reboot afterwards.

To summarize the steps (everything from 1 to 4 is from the other question; 5 and 6 are the different steps to do):

(1) Boot up the system, and after you see the BIOS screen press and hold "Shift" - you'll get the GRUB prompt.

(2) Use the 'recovery mode' option for your kernel - if it doesn't show up it's probably under the section for "Other Ubuntu versions" or one of the other items on Grub.

(3) Once in recovery mode, select the 'root' option by using the down arrow on your keyboard, and then hit Enter. You'll end up with a command line prompt for the root user.

(4) Remount your system as read/write with this command: mount -o remount,rw /

(5) Edit your /etc/passwd file with nano (use this command: nano /etc/passwd). Once you've edited the specific line for your user and reset it to 1000 for the UID and GID, hit Ctrl+O, then hit Enter, and then Ctrl+X.

(6) You should now be at the root terminal prompt again. Reboot with shutdown -r now or reboot.

You should then be able to login again, and have fixed your blunder. Don't go messing with your UID or GID, because setting yourself to 0 will break things and is horribly insecure and should never be done. (The 0 UID is for root, and root alone - DO NOT USE IT FOR ANY OTHER USER!)

大致步驟如下:

(1)重啓Ubuntu系統,在看到BIOS時快速按下shift鍵,進入GRUB嚮導

(2)選擇內核的修復模式(recovery mode)

(3)進入修復模式後選擇root,即可進入root命令行輸入界面

(4)鍵入命令:mount -o remount,rw /     獲得讀寫系統的權限

(5)使用命令:vi /etc/passwd或者nano /etc/passwd編輯passwd文件,將用戶賬號的UID改回原來的值並保存退出

(6)重啓系統,即可在桌面上再次看到可登陸用戶
--------------------- 
作者:yhl_sophia 
來源:CSDN 
原文:https://blog.csdn.net/yhl_sophia/article/details/88058312 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章