Python Unix 身份验证

发布于 2024-10-09 20:17:01 字数 722 浏览 0 评论 0原文

我需要对主机和 NIS 上的用户名进行简单的身份验证。 我正在用 Python 编写这段代码。
我尝试使用 PAM 进行身份验证。为此,我下载了一个名为 Python Pam 的 Python 模块。

我使用的代码:

import pam   
pam.authenticate('root',<password>,<service>)

其中 是我在 /etc/pam.d/ 中创建的配置文件
该文件包含以下代码

#%PAM-1.0
auth     requisite      pam_unix.so

此代码适用于某些给出正确答案的主机,但不适用于其他主机
即使我将 替换为登录名或 sshd,如所示,

pam.authenticate('root',<password>,'sshd')

对于某些主机上的正确密码,它仍然返回 False。

那么有人知道为什么这不起作用。我不需要使用 pam 或任何模块。 unix 中有没有可以从 Python 调用的命令来验证用户名?最好能在所有基于 UNIX 的系统上工作,包括 Linux、Solaris、HP-UX、AIX。
谢谢

I need to do a simple authentication of username's which are on the host and NIS.
I am writing this code in Python.
I tried using PAM to do authentication. For this I downloaded a Python module called Python Pam.

The code I use :

import pam   
pam.authenticate('root',<password>,<service>)

where <service> is a config file I created in /etc/pam.d/

the file contains the following code

#%PAM-1.0
auth     requisite      pam_unix.so

This code works on certain hosts giving the correct answer, but not on others
Even if I replaced <service> with login or sshd as in

pam.authenticate('root',<password>,'sshd')

It still returns False for a correct password on certain hosts.

So does anybody know why this does not work. I don't need to use pam or any module. Is there any command in unix that I can invoke from Python which would just authenticate a username? and preferably work across all unix based systems including Linux, Solaris, HP-UX, AIX.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-10-16 20:17:01

两者

 pam.authenticate('myusername', 'mypassword', 'sshd')

 pam.authenticate('myusername', 'mypassword')

登录在我的机器上运行良好。 pam 模块的文档几乎不存在,因此我很难说您的服务配置是否正确。

Both

 pam.authenticate('myusername', 'mypassword', 'sshd')

and

 pam.authenticate('myusername', 'mypassword')

Login works fine on my machine. The documentation for the pam module is pretty much non-existent, so if you configured your service correctly or not is hard for me to say.

不顾 2024-10-16 20:17:01

答案在于您创建的 /etc/pam.d/ 文件中的第三个参数。

在该命令不起作用的机器上尝试该命令。是的,您必须是 root 或 sudoer root。

# ldconfig -v |grep pam_unix.so

符号链接很可能不会从 pam_unix.so 引向真正的 pam 共享库。添加它或将配置文件参数更改为 ld 可以用来查找链接的内容。

The answer to that lies in the third parameter in the /etc/pam.d/ file you created.

Try this command on the machines where it does not work. Yes, you must be root or sudoer root.

# ldconfig -v |grep pam_unix.so

Most likely a symlink does not lead to the real pam shared library from pam_unix.so. Add it or change the config file parameter to something that ld can use to find the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文