首页 > 代码库 > 修改root密码
修改root密码
虚拟机修改root密码
1,挂载虚拟机的img 文件
mount -o loop,offset=$((512*1060290)) vm.img /opt/
chroot /opt
ONE-NODE239:/# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda2 3662668 1127288 2535380 31% /
proc 3662668 1127288 2535380 31% /proc
sysfs 3662668 1127288 2535380 31% /sys
debugfs 3662668 1127288 2535380 31% /sys/kernel/debug
udev 3662668 1127288 2535380 31% /dev
devpts 3662668 1127288 2535380 31% /dev/pts
proc 3662668 1127288 2535380 31% /var/lib/ntp/proc
ONE-NODE239:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root sbin srv sys tmp usr var
ONE-NODE239:/#
2,重挂根目录,使之可读写
ONE-NODE239:/# mount -o remount,rw /
3,修改root密码
a,如果此时改root密码出现如下错误
ONE-NODE239:/etc# passwd
Changing password for root.
New Password:
Bad password: too simple
Reenter New Password:
Cannot open /dev/urandom for reading: No such file or directory
Cannot create salt for blowfish crypt
Error: Password NOT changed.
passwd: Authentication token manipulation error
b,请执行以下步骤
exit
mount --bind /dev/ /opt/dev/
chroot /opt/
ONE-NODE239:/# passwd
Changing password for root.
New Password:
Bad password: too simple
Reenter New Password:
Password changed.
ONE-NODE239:/#
4,此时修改密码成功,我们需要卸载目录,重挂根,重启机器
# umount /opt/
umount: /opt: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
卸载报错
umount /opt/dev/
umount /opt
5,重启输入密码,修改成功。