问题原文
原帖链接 · BadToTheBone · CC BY-SA 3.0
I stumbled accross this problem when trying to create new FTP users for vsftpd. Upon creating a new user with the following command and attempting login with FileZilla, I would get an "incorrect password" error.
useradd f -p pass -d /home/f -s /bin/false
After doing this, /etc/shadow contains
f:pass:1111:0:99:2:::
Once I run the following command and provide the same pass pass
passwd f
/etc/shadow contains
f:$1$U1c5vVwg$x5TVDDDmhi0a7RWFer6Jn1:1111:0:99:2:::
It appears that encryption happens when I run passwd, but doesn't upon useradd
Importantly after doing this, I am able to login to FTP with the exact same credentials.
I am using CentOS 5.11, vsftpd for FTP, and FileZilla for FTP Access
/var/log/secure contains:
Dec 17 useradd[644]: new group: name=f, GID=511
Dec 17 useradd[644]: new user: name=f, UID=511, GID=511, home=/home/f, shell=/bin/false
Why does it not work when I pass -p pass to useradd? What do I need to do to make it work?
社区高分解答
原帖链接 · Dennis Williamson · CC BY-SA 3.0
useradd expects you to pass it the hash of the password, not the password itself. You can use the following variation on your command to provide a hashed password to the useradd command:
useradd f -p "$(mkpasswd --method=sha-512 'pass')" -d /home/f -s /bin/false
To find out the methods available, use:
mkpasswd --method=help
In order to avoid passing the password on the command line, put the password in a file (using an editor and not using echo or similar) and do this:
useradd f -p "$(mkpasswd --method=sha-512 --password-fd=0 < filename)" -d /home/f -s /bin/false
This will pass the hashed password on the command line, but not the plaintext one.
mkpasswd comes with the expect package.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
