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)重启系统,即可在桌面上再次看到可登陆用户

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值