背景:useradd sunny -p 123456;新建一个sunny用户,指定密码为123456,但是在登录sunny用户时却提示密码错误。
原因:useradd [USER_NAME] -p [PASSWORD]
这里的PASSWORD是加密过后的密码,而不是你登录时使用的未加密密码。
看下图:新建一个sunny用户,密码为123456,再查看/etc/shadow文件,可以看到密码那一列,其他的都是加密过的,而sunny用户显示的是你设置的密码,说明-p 指定的是加密过的密码。
如何解决?使用passwd [USER_NAME] 修改密码即可。
[root@master sunny-test]# passwd sunny
Changing password for user sunny.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@master sunny-test]#