Ubuntu, Debian, Kali, CentOS等linux重置root密码

来源:互联网 发布:淘宝怎么改会员名字 编辑:程序博客网 时间:2024/05/22 17:48

Forgetting root password is an hassle. We try to be vigilant with our security and set a complex root password. We also try not to login using directly into root account (in most production boxes) and use sudo instead. So it’s not very unlikely to loose your root password and depending on how you’ve setup your access, you just might not be able to reset it using sudo passwd root/someusername. Following post shows you two different ways to reset root password in Ubuntu, Debian, Kali, CentOS or pretty much any Linux distributions. Reset root password in Linux- blackMORE Ops - 1

Option 1: Reset root password from Grub

Step 1.1: Boot in to GRUB menu

Boot to the GRUB menu. Then, press e (for edit) before Linux has a chance to boot. (Most standard installation will allow you 5 seconds to choose and Boot option is Grub, so you’ve got plenty of time)

Step 1.2: Edit GRUB menu

Using your keyboard arrow keys, move the cursor down a line or so, and press e (for edit) again, you should now be on the kernel line, and pressEnd to go out to the very end of that line. Now hit the space-bar once, if necessary, to add a space, and then add one of the following:

init=/bin/bash(or)init=/bin/sh

Then press Enter, and you’re back at the kernel line, press b (for boot) and the computer will proceed to boot to a root prompt.

Step 1.3: Remount filesystem as Read/Write to save changes

At this point, the root file system is still mounted read-only, so enter the following command:

mount -n -o remount,rw /

Step 1.4: Reset root password / Change password

Then type:

passwd

Enter your new password. Retype if asked to confirm. Change your pw with a passwd command. If you’re not sure, man passwd should help.

Step 1.5: Reboot and off you go

Then restart the machine by typing:

reboot

Now you should be able to login with your new root password as required.

Option 2: Reset root password using a Live CD/DVD or Live USB

Using a Live Linux CD/DVD or Live USB is another option to reset root password if you’ve uncomfortable using Grub menu.

Following is what you do:

Step 2.1: Boot Computer using any Live Linux CD/DVD or USB

Start up the computer with a Linux live CD (or USB key). You can use any Linux distro such as Debian, Ubuntu or even Kali.

Step 2.2: Mount Filesystem

Using the Disk Utilities available from your device, mount the partition that hosts your /etc folder (probably marked as bootable).

Ideally following command does the trick

mount auto /dev/sdaX /mnt(or)sudo mount auto /dev/sdaX /mnt 

Where sdaX or similar is the partition that contains /etc folder.

Step 2.3: Identify correct shadow file in correct /etc folder

In a command line, go to ./etc under your mounted partition, probably in /mnt and contains a long hd id-like number. Notice the dot .before ./etc; don’t go to /etc. You can check that you’re in the right folder with grep -i [name of a user of yours (not root!)] shadow command. If you get anything, you’re in the right folder and you can proceed to Step 4.

Step 2.4: Make a backup of the shadow file

Just to be safe, make a backup copy of your shadow file. I used cp ./shadow /media/[an inserted and mounted USB key]/shadowcommand.

Step 2.5: Open shadow file using any text editor

Using your favorite text editor (vi, nano or pico), edit your shadow file

vi shadow (or) nano shadow (or) pico shadow

Step 2.6: Locate the root line

Locate the root line. It’ll look something like root:[encrypted pw]:12345:5:99999::: (You’ll have a some random numbers is there)

Step 2.7: Replace encrypted password line

Replace the [encrypted pw] part of the line with a single ! exclamation mark without double quotations. That tells Linux to authorize the mentioned user to access the system with no pw, so be cautious ! Your line will then look something like root:!:12345:5:99999:::

Step 2.8: Save changes

Save your changes and exit the command line

Step 2.9: Unmount the partition

Back to your Disk Utilities program, unmount the partition you mounted in step 2 above.

umount /dev/sdaX (or)sudo umount /dev/sdaX 

Where sdaX or similar is the partition that contains /etc folder.

Step 2.10: Poweroff and remove boot media

Poweroff your computer and remove all media, may it be USB key, CD, or whatever.

Step 2.11: Restart and boot into rescue mode

Now start/restart your computer and, in the grub menu, choose rescue mode. You’ll find yourself in a command line of a root session with no pw.

Step 2.12: Reset root password / Change password

Change your password with a passwd command. If you’re not sure, man passwd should help. Once done, you can restart again and now you should be able to login as root user from terminal (maybe not from SSH depending on how you’ve configured your SSH server). So there you go, two options to reset root password in Ubuntu, Debian, Kali, CentOS or pretty much any Linux distributions.

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 天竺葵花骨朵有虫子了怎么办? 被刺梅的刺扎了怎么办 被刺梅的刺划手了怎么办 虎刺花叶子黄了怎么办 地栽月季叶子发黄怎么办 梅花浇水浇多了怎么办 深水井底下花管进水量小怎么办 盆景对节白腊树叶尖干枯怎么办 四季海棠茎软了怎么办 玫瑰海棠烂根了怎么办 格丽海棠花腌了怎么办 养殖场不能雨污分流怎么办 药店买的药贵了怎么办 神经损伤小便少尿不出来怎么办 手指夹伤出血了怎么办 手指夹破流血了怎么办 喂了宝宝熊胆粉怎么办 不小心擦伤了皮怎么办 吃了减肥药拉肚子怎么办 遇到他心通的人怎么办 被茅山术害了怎么办 鱼缸鱼身上烂了怎么办 鳄鱼龟皮肤烂了怎么办 墨水渗透进皮肤里了怎么办 中药渗透到皮肤里怎么办 甘露醇渗透到皮肤下怎么办 水银弄到眼睛里怎么办 水银粘到皮肤上怎么办 榴莲和虾同吃了怎么办 吃榴莲和虾中毒怎么办 榴莲和虾一起吃怎么办 狗被别人下毒了怎么办 大掌门2没存元宝怎么办 大掌门2转换阵容怎么办 率土之滨s2绝版怎么办 异界气息的装备怎么办 vivo电板没电了怎么办 门套拼接有缝隙怎么办 公司如果一直没有上税收入怎么办 赛车输了俩百万怎么办 交pk金员工不交怎么办