大网数据广告活动
服务器运维问答

useradd not encrypting passwords in /etc/shadow

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-12-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。