$ sudo su $ vi /etc/hostname
Modify hosts file
After changing and restarting the computer, you can see that the host name has been modified.
Usually, the failure to log in again after restart due to an error occurs in this link, so it is necessary to modify it carefully in the following order
- (1) Modify sudoer file
We need to give higher permissions to the name we want to change in advance to prevent insufficient permissions in the process of modifying the following files.
- (2) Modify shadow file
This file is stored in the file related to login. The content related to login is stored in the following format: username: passwd: lastchg: min: max: warn: inactive: expire: flag Login name: encryption password: last modification time: minimum time interval: maximum time interval: warning time: inactive time: expiration time: Flag
$ vi /etc/shadow
Just modify the previous user name
- Modify directory
$ cd /home/ $sudo MV test username
- Modify passwd file
$ vi /etc/passwd
The content format of passwd file is as follows: User name: Password: uid: GID: user description: Home Directory: login shell
We changed the user name and home directory to a new name (5) If we also want to modify the group to which the file under the original user belongs: We can also change the old user group in the / etc / group file to a new user group (6) Finally, enter the / etc / sudoer file again and delete the old user name XXX Restart and log in again. We will find that the user name and host name have been changed successfully.
The general steps are as follows
The user name of Ubuntu is changed to robot, please modify it in order 1. Modify sudoer file sudo gedit /etc/sudoers 2. Modify shadow file The contents related to login are stored in this file. The format is as follows: username: passwd: lastchg: min: max: warn: inactive: expire: flag Login name: encryption password: last modification time: minimum time interval: maximum time interval: warning time: inactive time: expiration time: Flag sudo gedit /etc/shadow Modify login 3. Modify the start directory (this step must be, otherwise an error will occur) cd /home/ sudo mv test robot 4. Modify password file sudo gedit /etc/passwd 5. Modify user group If you need to modify the user group, change the user in / etc / group to robot 6. Finally, enter the / etc / sudoer file again and delete the user name user 7. Restart and log in again, and the user name will be modified successfully
This work adoptsCC agreement, reprint must indicate the author and the link to this article