误改 /etc/passwd 中的uid/gid 导致账号无法登录

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
svitian
帖子: 5
注册时间: 2017-09-23 19:56

误改 /etc/passwd 中的uid/gid 导致账号无法登录

#1

帖子 svitian » 2017-09-23 20:04

今天手贱,想提升权限sudo gedit /etc/passwd
把x:1000:1000:crystal:/home/linuxidc:/bin/bash 从1000改到0
再重启默认的账户消失了。只有来宾登录。
请大侠帮忙。。。万分火急。
头像
qy117121
论坛版主
帖子: 50546
注册时间: 2007-12-14 13:40
系统: Winbuntu
来自: 志虚国乌由市
联系:

Re: 求助

#2

帖子 qy117121 » 2017-09-23 20:56

用恢复模式或者livecd 什么的改回来
渠月 · QY   
本人只会灌水,不负责回答问题
无聊可以点一下→ http://u.nu/ubuntu

Ubuntu 20.04 快速设置指南,请配合浏浏览器自动翻译使用

邮箱 chuan@ubuntu.org.cn
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 求助

#3

帖子 科学之子 » 2017-09-23 21:19

也可以给内核传init=/bin/bash参数来直接进入bash修改
修改后重启前记得用sync命令同步磁盘,不然重启后可能修改内容丢失.
svitian
帖子: 5
注册时间: 2017-09-23 19:56

Re: 求助

#4

帖子 svitian » 2017-09-23 21:33

科学之子 写了:也可以给内核传init=/bin/bash参数来直接进入bash修改
修改后重启前记得用sync命令同步磁盘,不然重启后可能修改内容丢失.
qing wen ju ti ru he chao zuo ?
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 求助

#5

帖子 科学之子 » 2017-09-24 2:32

svitian 写了:
科学之子 写了:也可以给内核传init=/bin/bash参数来直接进入bash修改
修改后重启前记得用sync命令同步磁盘,不然重启后可能修改内容丢失.
qing wen ju ti ru he chao zuo ?
2楼方法其实更简单,建议您优先尝试.
我说的只是一个不同的方法,仅供参考.
在引导菜单按照提示选择编辑相应的菜单项(即进入相应菜单项的编辑模式),进入编辑模式后给带有vmlinuz那行最后面加上" init=/bin/bash"(注意空格)
进入后用vi改.要是vi丝毫简单编辑都不会用,试着用nano代替vi进行这种简单编辑.
还是不会用,那我的方法就完全不适合您了,请无视...
我这个方法的优点就是无需livecd,当然也是简单粗暴.
再次提醒:我这个方法进入的系统没法正常开关机,所以必须用sync命令同步一下磁盘再重启.
希望没白说这么多.
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 求助

#6

帖子 poloshiao » 2017-09-24 6:15

今天手贱,想提升权限sudo gedit /etc/passwd
把x:1000:1000:crystal:/home/linuxidc:/bin/bash 从1000改到0
再重启默认的账户消失了。只有来宾登录。
新手 如果是 Ubuntu 桌面作業系統 不建議直接去改 uid/gid
如果是安裝 ubuntu 時 創建的帳號登入
需要使用 root 權限時
sudo + 文字指令
gksudo + gnome-圖形指令 (需要先安裝 gksu 套件)
kdesudo + kde-圖形指令 (需要先安裝 kdesudo 套件)
svitian
帖子: 5
注册时间: 2017-09-23 19:56

Re: 求助

#7

帖子 svitian » 2017-09-24 7:57

已在askubuntu找到答案,并已经修复了。谢谢各位。。
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 求助

#8

帖子 科学之子 » 2017-09-25 4:33

svitian 写了:已在askubuntu找到答案,并已经修复了。谢谢各位。。
罗嗦一句:相比说一句"已在askubuntu找到答案"不如直接复制粘贴网址链接来的快捷有效.(当然如果是手机之类的不方便复制的情况除外)
svitian
帖子: 5
注册时间: 2017-09-23 19:56

Re: 误改 /etc/passwd 中的uid/gid 导致账号无法登录

#9

帖子 svitian » 2017-10-01 19:34

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!)
头像
TeliuTe
论坛版主
帖子: 7668
注册时间: 2007-11-25 13:29
系统: 16/18/20/w7
来自: 新疆博乐
联系:

Re: 误改 /etc/passwd 中的uid/gid 导致账号无法登录

#10

帖子 TeliuTe » 2017-10-01 20:39

原来要remount rw一下,难怪上次修改怎么也保存不了,最后重装了事
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 误改 /etc/passwd 中的uid/gid 导致账号无法登录

#11

帖子 科学之子 » 2017-10-02 22:26

TeliuTe 写了:原来要remount rw一下,难怪上次修改怎么也保存不了,最后重装了事
Ubuntu 不确定, Debian 的话给内核引导参数加上 rw 就不用 remount 了.
不知发行版为何默认是 ro ,我这里 ro 的话根分区就是只读,会导致系统无法正常运行.
回复