[HOW TO] useradd: unable to open password file

Hello Buddy,

In the mid night I have just found what is needed. It's simple.

When I created/deleted/modified an account in CentOS 6, I'm getting error:

userdel: cannot open /etc/passwd

Damn, I tried to fix it  but ... 

At the moment, my buddy call me that invite me out for lunch. I temporarily forget it. Let's go!

After come back home. Laptop, I need to start it to resolve a little shit.

And it make me happy when I solved the problem.

You can fix the following me.

[root@centos01 ~]# userdel -r dtdong
userdel: cannot open /etc/passwd
[root@centos01 ~]#
[root@centos01 ~]# userdel dtdong
userdel: cannot open /etc/passwd
[root@centos01 ~]# chattr -ai /etc/passwd
[root@centos01 ~]#
[root@centos01 ~]# userdel -r dtdong
userdel: cannot open /etc/shadow
[root@centos01 ~]#
[root@centos01 ~]# chattr -ai /etc/shadow
[root@centos01 ~]# userdel -r dtdong
userdel: cannot open /etc/group
[root@centos01 ~]# chattr -ai /etc/group
[root@centos01 ~]# userdel -r dtdong
userdel: cannot open /etc/gshadow
[root@centos01 ~]# chattr -ai /etc/gshadow
[root@centos01 ~]# userdel -r dtdong
[root@centos01 ~]#

Happy =))

That may mean that your /etc/passwd file is not set properly for access. Therefore, you must to use the chattr command to set properly for access.

Why? What is chattr?

I will explain about chattr command. Chattr attribute is used to stop accidentally delete of files and folders. You can not delete the files secured via chattr attribute event though you have full permission over files. This is very use full in system files like shadow and passwd files which contains all user information and passwords.

Syntax for chattr command is

#chattr [operator] [switch] [file name]

The operator "+" causes the selected attributes to be added to the existing attributes of the file. "-" causes them to be removed, and "=" causes them to be the only attributes that the files have.

-R
Recursively change attributes of directories and their contents. Symbolic links encountered during recursive directory traversals are ignored.

-a
set can only be open in append mode for writing. Only the superuser can set or clear this attributes.

-i
A file with the "i" attributes cannot be modified, cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser can set or clear this attributes.




Thank you for reading this article, please a comment if you are interested.
Tiến Phan - R0039
Knowledge is Endless
Sharing for Success
.









1 comment: