给定一个Linux用户名和密码我怎么测试它是否是一个有效的帐户? [英] Given a linux username and a password how can I test if it is a valid account?

查看:145
本文介绍了给定一个Linux用户名和密码我怎么测试它是否是一个有效的帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的问题是直接给出一个linux用户名和密码,我该如何测试它是否是一个有效的帐户?

解决方案

您可以使用影子文件验证给定用户名的密码是否正确。



在大多数现代发行版中,散列密码存储在影子文件/ etc / shadow(它只能被root用户读取)。以root用户的身份从给定用户的影子文件中提取行,如下所示:

  cat / etc / shadow | grep username 

您会看到类似这样的内容:

 用户名:$ 1 $ TrOIigLp $ PUHL00kS5UY3CMVaiC0 / g0:15020:0:99999:7 ::: 

用户名后有$ 1。这表明它是一个MD5散列。之后有另一个$,然后(在这种情况下)TrOIigLp后跟另一个$。 TrOIigLp是盐。之后是散列的密码,使用盐进行散列 - 在这种情况下,PUHL00kS5UY3CMVaiC0 / g0。

现在,您可以使用openssl对给定密码进行散列盐,就像这样:

  openssl passwd -1 -salt TrOIigLp 

出现提示时输入给定密码,openssl命令应该使用提供的salt计算MD5哈希值,它应该与影子文件中的上述内容完全相同。上述命令中的-1用于MD5哈希。


So my question is straight forward given a linux username and a password how can I test if it is a valid account?

解决方案

You can validate that a given password is correct for a given username using the shadow file.

On most modern distributions, the hashed passwords are stored in the shadow file /etc/shadow (which is only readable by root). As root, pull the line from the shadow file for the given user like so:

cat /etc/shadow | grep username

You will see something like this:

username:$1$TrOIigLp$PUHL00kS5UY3CMVaiC0/g0:15020:0:99999:7:::

After the username there is $1. This indicates that it is an MD5 hash. After that there is another $, then (in this case) TrOIigLp followed by another $. TrOIigLp is the salt. After that is the hashed password, which was hashed using the salt - in this case PUHL00kS5UY3CMVaiC0/g0.

Now, you can use openssl to hash the given password using the same salt, like so:

openssl passwd -1 -salt TrOIigLp

Enter the given password when prompted, the openssl command should compute the MD5 hash using the salt provided, and it should be exactly the same as the above from the shadow file. The -1 in the above command is for MD5 hashing.

这篇关于给定一个Linux用户名和密码我怎么测试它是否是一个有效的帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆