Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the ROOT password can not be modified in ubuntu

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Ubuntu can not modify ROOT password how to solve, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

I. Version View

Command cat /etc/issue

Second, enter single user mode

Press CTRL+ALT+DEL to restart the system, then press any key to stop grub:

Select Advanced options for Ubuntu

Next Next post: Recovery Mode

Press e to enter editing mode.

Change the "ro " at the end of the linux opening line to "rw single quiet splash init=/bin/bash" or "rw single init=/bin/bash"

(Note: ro is read-only mode, rw is read-write mode.)

Then press CTRL+X or F10 to enter Single User Mode.

Note: If RO is not changed to RW in this place, you can enter #mount -rw -o mount/(mount -no mount,rw / mount -a) after single user, otherwise the file system is in read-only mode at this time, and/etc/passwd and/etc/shadow cannot be modified.

Third, change the password

First, check whether there is any exception in the permission.

# ll /etc/passwd

-rwxr-r- 1 root root 2752 Dec 11 10:29 /etc/passwd

# fuser -u /etc/passwd

# lsof |grep passwd

Trying to change the password again still fails, so trying to change/etc/passwd also fails

# chmod 777 /etc/passwd

chmod: changing permissions of `/etc/passwd': Operation not permitted

Execute chattr

# chattr -i /etc/passwd

# lsattr -v /etc/passwd

2095582053 ----- /etc/passwd

# chattr -i /etc/shadow

# lsattr -v /etc/shadow

Then synchronize passwd and shadow files

pwconv

Finally successfully changed the password

passwd root

Changing password for user root.

New UNIX password:

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

Additional knowledge:

PS: Sometimes you find that you cannot modify a file with root privileges, mostly because you have locked the file with chattr. The chattr command is very useful, some of which are supported by Linux kernel versions, but most of the Linux systems that run now are kernel 2.6 or higher. Changing attributes via chattr can improve system security, but it is not suitable for all directories. The chattr command does not protect/,/dev,/tmp,/var directories. The lsattr command displays file attributes set by the chattr command.

These two commands are used to view and change file, directory attributes, and chmod compared to this command, chmod only change the file read and write, execute permissions, the lower level of attribute control is changed by chattr.

chattr [ -RVF ] [ -v version ] [ mode ] files…

The key is in the [mode] section, which is composed of +-= and [ASacDdIIjsTtu] characters, which are used to control file attributes.

+ : Add parameters based on the original parameter settings.

- : Remove parameters based on original parameter settings.

=: Update to specified parameter settings.

A: The atime (access time) of a file or directory cannot be modified, which can effectively prevent I/O errors such as laptop disks.

S: Hard disk I/O synchronization option, similar to sync.

a: Append, after setting this parameter, you can only add data to the file, but not delete it. It is mostly used for server log file security. Only root can set this attribute.

c: compresse, setting whether the file is compressed before storage. Automatic decompression is required when reading.

d: No dump, the settings file cannot be a backup target for the dump program.

i: Setting file cannot be deleted, renamed, set link relationship, and cannot be written or added. The i parameter is very helpful for file system security settings.

j: journal, this parameter is set so that when a file system is mounted via the mount parameter: data=ordered or data=writeback, the file is recorded first (in journal) when written. If filesystem is set to data=journal, this parameter is automatically disabled.

s: Delete files or directories confidentially, i.e. all hard disk space is reclaimed.

u: Contrary to s, when u is set, the data content is actually still on disk and can be used for undeletion.

A and i are commonly used in various parameter options. A option forces only undeletable additions, mostly used for security settings for logging systems. While i is a more stringent security setting, only superuser (root) or processes with CAP_LINUX_IMMUTABLE processing capability (identity) can impose this option.

Application examples:

1. Use the chattr command to prevent a key file in the system from being modified:

# chattr +i /etc/resolv.conf

Then use mv /etc/resolv.conf and other commands to operate on this file, all of which result in Operation not permitted. W10: Warning: Changing a readonly file error appears when vim edits the file. To modify this file,

To remove the i attribute: chattr -i /etc/resolv.conf

# lsattr /etc/resolv.conf

The following properties are displayed

----i-------- /etc/resolv.conf

2, so that a file can only add data to it, but can not be deleted, applicable to various log files:

# chattr +a /var/log/messages

CHATTR and LSATTR

If you previously configured your system for security, set/etc/passwd, /etc/shadow to unmodifiable

Then you need to cancel the previous changes, as follows:

[root@station22 ~]# lsattr /etc/passwd /etc/shadow

----i-------- /etc/passwd

----i-------- /etc/shadow

[root@station22 ~]# chattr -i /etc/passwd

[root@station22 ~]# chattr -i/etc/shadow

[root@station22 ~]# lsattr /etc/passwd /etc/shadow

------------- /etc/passwd

------------- /etc/shadow

You can change the root password.

After modification, execute

[root@station22 ~]# chattr +i /etc/passwd

[root@station22 ~]# chattr +i/etc/shadow

After reading the above, do you know how to solve the problem of not being able to modify ROOT password in ubuntu? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report