Forgot root password how to solve? How do I implement two Linux logins after cloning a virtual machine?

Source: Internet
Author: User

To change the root password using single-user mode hack:


1, if you forget the root password of Linux, you can enter the single-user mode to change the root password, first we restart the virtual machine, the operation is as follows:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s3.51cto.com/oss/201710/19/988b07472f0cf6a2f39e5fa14cef3bfe.png-wh_500x0-wm_3-wmp_4-s_1867563961.png " Title= "1.png" alt= "988b07472f0cf6a2f39e5fa14cef3bfe.png-wh_"/>

2, restart the system, 3 seconds to press the downward direction key, let it stay in the boot interface, such as:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s2.51cto.com/oss/201710/19/420d8b2877b3be340d82c941fa81460a.png-wh_500x0-wm_3-wmp_4-s_2924398204.png " Title= "2.png" alt= "420d8b2877b3be340d82c941fa81460a.png-wh_"/>

3, by the direction of the key to stay in the first line, the letter E to edit it, and then enter another interface, through the downward direction key to the beginning of the Linux 16 line, the RO changed to RW Init=/sysroot/bin/bash, such as:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/ef55db72e53ca062f600a3eeb31b96bc.png-wh_500x0-wm_3-wmp_4-s_106122589.png " Title= "3.png" alt= "Ef55db72e53ca062f600a3eeb31b96bc.png-wh_"/>

4, after the completion and then directly press CTRL+X, the system will enter the following interface, so formally into the emergency mode.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s5.51cto.com/oss/201710/19/f90fe23e3305cbfc801d75e9d243d377.png-wh_500x0-wm_3-wmp_4-s_4041574125.png " Title= "4.png" alt= "F90fe23e3305cbfc801d75e9d243d377.png-wh_"/>

5, first switch to the original system, and then modify the root password, the operation process

Description: The chroot command is used to switch the system, the/sysroot directory is the original system (that is, our CentOS7 system), the passwd command is the command to modify the root password. Because vmwave inside it does not support Chinese, the appearance of small squares commonly known as garbled, input lang=en, this command is the current terminal language set to English. After the password is changed, an additional action is required, enter the command: Touch/.autorelabel then press ctrl+d, enter the command reboot restart, complete the change.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s5.51cto.com/oss/201710/19/df68069bbbe50b131a12f22d1ddff08b.png-wh_500x0-wm_3-wmp_4-s_679596194.png " Title= "5.png" alt= "Df68069bbbe50b131a12f22d1ddff08b.png-wh_"/>


Use rescue mode to crack change root password:


Note: Rescue mode (that is, Rescus mode, this mode is mainly used in cases where the system is inaccessible, such as grub corruption or a profile modification error, such as Grub set the password you do not remember that you can not use a single user to change the root password, so to enter the rescue mode to change the password)


1. Set the disc to boot on the VM virtual machine.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s2.51cto.com/oss/201710/19/7985a0dcba7902031c6cd28590a81ee7.png-wh_500x0-wm_3-wmp_4-s_3601297362.png " Title= "6.png" alt= "7985a0dcba7902031c6cd28590a81ee7.png-wh_"/>

2. After the setup is complete, select the virtual machine on the left side of VMware and right click, select "Power"-"Enter firmware when power is on", and the final result to the second picture.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s3.51cto.com/oss/201710/19/84f733d57b5caabc25d75ff27da82cc2.png-wh_500x0-wm_3-wmp_4-s_2741435950.png " Title= "7.png" alt= "84f733d57b5caabc25d75ff27da82cc2.png-wh_"/>

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201710/19/0d1172844b5af52fdfccbc7cce97e0fa.png-wh_500x0-wm_3 -wmp_4-s_1277700772.png "title=" 8.png "alt=" 0d1172844b5af52fdfccbc7cce97e0fa.png-wh_ "/>

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/> After setting this step, simply press F10 to save the settings and exit the system.

3, with access to the CD-ROM boot interface, use the upper and lower arrow keys to select Troubleshooting Enter.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s5.51cto.com/oss/201710/19/a9a3c7f714e9a1c40b38fd8e1c216be7.png-wh_500x0-wm_3-wmp_4-s_659259229.png " Title= "9.png" alt= "A9a3c7f714e9a1c40b38fd8e1c216be7.png-wh_"/>

4, enter the following interface, use the DOWN ARROW key to select Rescue a CentOS Linux system

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s4.51cto.com/oss/201710/19/58fcbe1be881d45ce5d55e06297d629e.png-wh_500x0-wm_3-wmp_4-s_1269808607.png " Title= "10.png" alt= "58fcbe1be881d45ce5d55e06297d629e.png-wh_"/>

5, the connection knocks two times the carriage return, appears the interface as follows

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/02e07d050e9dc0cc1486d3aa9700ee58.png-wh_500x0-wm_3-wmp_4-s_3045869064.png " Title= "11.png" alt= "02e07d050e9dc0cc1486d3aa9700ee58.png-wh_"/>

Note: There are some hints that it tells us that the initial system is under/mnt/sysimage, which is actually similar to the/sysroot in the previous section. Here are 4 options: Select the 1th item will continue to go down, select the 2nd will mount the initial system as read-only mode, we can not write the disk, it means that the configuration file can not be modified, or change the root password, select the 3rd item will appear directly a shell, and the selection of the 4th will be restarted.

6, here Select the 1th entry, enter the number "1", carriage return after the return, it again told us: the initial system has been mounted to the/mnt/sysimage below, to enter the initial system below, you need to execute the chroot/mnt/sysimage command

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s4.51cto.com/oss/201710/19/2b813f69c48041a8723a2d317361e3c6.png-wh_500x0-wm_3-wmp_4-s_3527091701.png " Title= "12.png" alt= "2b813f69c48041a8723a2d317361e3c6.png-wh_"/>

7. After entering the initial system, execute the command passwd to change the root password, such as:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/02c5d6f44830e91cc31ec166c945efda.png-wh_500x0-wm_3-wmp_4-s_2167876246.png " Title= "13.png" alt= "02c5d6f44830e91cc31ec166c945efda.png-wh_"/>

Note: After executing the chroot command, you will notice that there are some changes in the command line, that is, the original sh-4.2 becomes bash-4.2, because the environment variable has changed. Complete the root password modification, of course, rescue mode is not only to change the root password so simple role, we can also in rescue mode to deal with some failures, repair data, etc.

8. After the root password has been modified, press Ctrl+d to exit the original system, then perform the reboot or init 0 command to restart or shut down, then enter the BIOS setup hard drive for the first boot system or set VMware to turn off the optical drive after shutting down the computer.


To clone a virtual machine:


Note: You will need more than one virtual machine when you are doing the experiment, of course you can also reinstall one, but in order not to waste time, there is another way is to clone the virtual machine.

1. Close the running Linux system, the shutdown command has init 0 or shutdown-h Now, then right-click on the corresponding virtual machine name on the left, select "Manage", then "clone", such as:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s5.51cto.com/oss/201710/19/aef93b2cb8b34cec76d48724ac8def00.png-wh_500x0-wm_3-wmp_4-s_2877059325.png " Title= "14.png" alt= "Aef93b2cb8b34cec76d48724ac8def00.png-wh_"/>

2, the "Clone Wizard" screen appears, click on the "Next" button, then click the "Next" button, select "Create Link Clone", this type is more convenient to save time, continue to click the "Next" button, then you can set the clone virtual machine name and save the path, then click "Done", Finalize virtual machine cloning.

3, the clone completed virtual machine, login system, because the two system IP is the same, so we want to edit the NIC configuration file change IP, enter VI/ETC/SYSCONFIG/NETWORK-SCRIPTS/IFCFG-ENS33, and then modify the IP, Delete the UUID line, save exit, then enter SYSTEMCTL Restart Network.service Restart the NIC service to complete the change.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/9978970e365e2474e8734bc2e7c577ee.png-wh_500x0-wm_3-wmp_4-s_2460236459.png " Title= "15.png" alt= "9978970e365e2474e8734bc2e7c577ee.png-wh_"/>

4, and then put another virtual machine also boot up, change the hostname, enter the Hostnamectl set-hostname host name, enter the completion of changes, input hostname view hostname, complete.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/7676a0ca2b4ca202f463620c57af9144.png-wh_500x0-wm_3-wmp_4-s_535640180.png " Title= "16.png" alt= "7676a0ca2b4ca202f463620c57af9144.png-wh_"/>


Linux machines log in to each other:


Log in with a password:


1. The Linux virtual machine telnet to aminglinux-01 via Xshell, then executes the following command on the first machine:

[[email protected] ~]# ssh 192.168.1.237

The authenticity of host ' 192.168.1.237 (192.168.1.237) ' can ' t be established.

ECDSA key fingerprint is 89:19:99:8c:63:ff:d9:e6:19:0d:81:03:27:54:49:78.

Is you sure want to continue connecting (yes/no)? Yes //First time login to the other machine, there is a hint

Here we directly enter Yes, and then enter, the following warning appears, it means to save the 192.168.1.237 this machine information:

warning:permanently added ' 192.168.1.237 ' (ECDSA) to the list of known hosts.

[email protected] ' s password:

After entering the root password of 192.168.1.237, log in to aminglinux-01 the machine successfully

Last Login:thu Oct 19:31:23 from 192.168.4.84

[Email protected] ~]#

Note: You can use WhoAmI to view the current logged-in user, the standard connection is SSH [email protected] that is SSH [email protected] , command w to view the system load such as:

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201710/19/793611b16a03eda7bc3cd10ca769a1e8.png-wh_500x0-wm_3 -wmp_4-s_1520941997.png "title=" 17.png "alt=" 793611b16a03eda7bc3cd10ca769a1e8.png-wh_ "/>


Tip: SSH default port is 22, from the above connection we can see, we are directly remote connection, assuming that some machine port is not 22 but other, then we need how to connect, you can enter the command: ssh-p [email protected]

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= " Https://s1.51cto.com/oss/201710/19/cb9e2a6abc77115d03f84fbda94ab6a6.png-wh_500x0-wm_3-wmp_4-s_2124004321.png " Title= "18.png" alt= "Cb9e2a6abc77115d03f84fbda94ab6a6.png-wh_"/>


Login with key:


1, Linux has a tool called Ssh-keygen, in the Linux machine directly input, as follows.


[Email protected] ~]# Ssh-keygen

Generating public/private RSA key pair.

Enter file in which to save the key (/ROOT/.SSH/ID_RSA):

Enter passphrase (empty for no passphrase):

Enter same Passphrase again:

Your identification has been saved In/root/.ssh/id_rsa. Private

Your public key has been saved in/root/.ssh/id_rsa.pub. Public

The key fingerprint is:

34:8c:69:21:37:db:d5:8c:14:b2:a2:bd:a8:1f:7c:11 [email protected]

The key ' s Randomart image is:

+--[RSA 2048]----+

| . + .. +=     |

| o O +. o |

| E * |

|       + + . |

| . o S |

| . . o |

| + O |

| . o |

| ...            |

+-----------------+

[Email protected] ~]#


You can also view the private key and public key file directory by command ls/root/.ssh/, as follows:


[Email protected] ~]# ls/root/.ssh/

Authorized_keys Id_rsa id_rsa.pub known_hosts


Note: If a machine logs on to another machine, then we need to copy the public key on this machine to another machine, the two are a pair, assuming that the 02 machine is logged into the 01 machine through the key, the 02 machine needs the private key, 01 the machine needs the public key.


2, we from 02 this machine input command cat/root/.ssh/id_rsa.pub, the public key is copied out, as follows.


[Email protected] ~]# cat/root/.ssh/id_rsa.pub

Ssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqc6xik5bbspekn8iii1grn0w1c2h0ivq6getjulq/aepnfh06rduxqujac2tgdrrdekseedkj/ wnrhrjd7hkms27xa3ynwoz0gtjshskxinwyktxwumszm825yfwcuhrv4nvwjty6gfnbjeiy57rjtmlo1lve+unoq686xq/wqh0eumyrknk+ ocopxlewvsbsprzl+tpwjkdl36ohdfggvjjmbfsqa8hgd5f4++aqf4tws5x/f/4gbjmuavt4ibxnbbl2ikneq// uzggve7tgwhullxwqn5gejlcqgyasbxfzjx1uqkyanwzhovhjfgfwfg0bzk5j0qcqfbh+mkp+b7 [email protected]


3, the public key copied from the 02 machine to 01 machine, in 01 machine input command VI/root/.ssh/authorized_key Enter open the public key paste in, save exit.


4, check getenforce view status, temporarily shut down SELinux this firewall. As follows:


[Email protected] ~]# Getenforce

Enforcing

[Email protected] ~]# Setenforce 0

[Email protected] ~]# Getenforce

Permissive

[Email protected] ~]#


5, verify the use of key login success, without password, complete.


[Email protected] ~]# ssh-p [email protected]

Last Login:thu Oct 20:20:05 from 192.168.1.238

[Email protected] ~]#


This article is from the "Gary Blog" blog, please be sure to keep this source http://taoxie.blog.51cto.com/10245493/1974371

Forgot root password how to solve? How do I implement two Linux logins after cloning a virtual machine?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.