Linux – SSH failing authentication after manual edit of /etc/passwd and /etc/shadow

centoslinuxssh

Recently, I needed to add a user to our CentOS server. For some reason, I could not add or remove them using useradd or userdel, so I edited /etc/passwd and /etc/shadow manually, adding them. I was then able to use passwd as root to change their password, and all was well.

Or so I thought. Now, some users aren't able to log in via SSh at all – when prompted for their password, they're given Permission denied, please try again. for three attempts, then Permission denied (publickey,gssapi-with-mic,password).

This may be unrelated to the changes to /etc/passwd and /etc/shadow – removing the changes to those files doesn't solve the problem.

EDIT 1: The new user is able to log in via ssh, but some older users (including root) are not. The problem is also ONLY with ssh – logging in on the physical machine, and using su, both work without problem.

Best Answer

I think adding users manually to /etc/passwd and /etc/shadow is a bad idea. Those users may face troubles sooner or later. Also, you may mistype some records. I am not sure what will be the result in this case.

I recommend you to restore these files to the old state if possible and retry adding those users using useradd command.

Related Topic