简体   繁体   English

如何在ubuntu / linux中添加基于面部识别的登录?

[英]How to add facial recognition based login in ubuntu/linux?

I have written a code (in python) to detect my face. 我已经用python编写了代码来检测我的脸。 Now I want to add this feature for login in my Ubuntu system. 现在,我想添加此功能以在我的Ubuntu系统中登录。 I searched over internet but cannot find suitable answers. 我通过互联网搜索,但找不到合适的答案。

I want to display an option/icon to select facial recognition and on clicking that, my facial recognition code starts running in background. 我想显示一个选项/图标以选择面部识别,然后单击它,我的面部识别代码开始在后台运行。 How I can achieve it? 我该如何实现? Please explain exactly where I need to make changes in ubuntu system for enabling and using such option? 请确切说明我需要在ubuntu系统中进行哪些更改才能启用和使用该选项?

You will want to use Linux-PAM to allow you to Su/Sudo using facial recognition. 您将要使用Linux-PAM允许您使用面部识别来Su / Sudo。 I have done this with python + a bash script here: https://github.com/lambrou/susentry I have taken part of my README and will explain it to you with the context of your question. 我已经在这里用python + bash脚本完成了此操作: https : //github.com/lambrou/susentry我已经参加了自述文件,并将根据您的问题向您解释。

The first thing you will need to do is make a bash script that calls your python script. 您需要做的第一件事是制作一个bash脚本来调用您的python脚本。

#!/bin/bash

# You must change the value /path/to/susentry.py to the path of your
# python file.
export DISPLAY=:0.0
xhost +local:
python3 /path/to/susentry.py -l # run the python script for facial recognition
exit_status=$? # This grabs the exit status of the python script we just ran
if [ "${exit_status}" -ne 0 ]; # checks to see if exit status is anything other than 0
then
    echo "exit ${exit_status}"
    exit 1 # exit status 1 on python script fail (exit 1)
fi
echo "EXIT 0"
exit 0 # exit 0 if we get to this line

What this script does is sets the display to your display, as the PAM module will be calling the script from a different userspace we will need to tell it where your display is, and what xhost you are using. 该脚本的作用是将显示设置为您的显示,因为PAM模块将从另一个用户空间调用该脚本,我们需要告诉它您的显示在哪里以及您使用的xhost。 Then, it grabs the exit status of your python script (make sure on facial recognition fail it exits 1, pass it exits 0) and passes it to PAM to let it know whether or not the script passed or failed. 然后,它获取python脚本的退出状态(确保在面部识别失败后退出1,通过退出0)并将其传递给PAM,以告知脚本脚本是否通过或失败。 Find this line: 找到这一行:

python3 /path/to/susentry.py -l python3 /path/to/susentry.py -l

And change /path/to/susentry.py to the full path of your python script. 并将/path/to/susentry.py更改为python脚本的完整路径。 Then, place this file in /usr/local/bin folder. 然后,将此文件放在/ usr / local / bin文件夹中。

Next, we modify the PAM common-auth file: 接下来,我们修改PAM common-auth文件:

gksudo gedit /etc/pam.d/common-auth

Find this line in your common-auth file: 在您的common-auth文件中找到以下行:

auth [success=1 default=ignore]     pam_unix.so nullok_secure

This line calls the module that asks the user for a password. 该行调用要求用户输入密码的模块。 If the module returns success (password correct), it skips the next line (success=1 means skip one line). 如果模块返回成功(密码正确),则跳过下一行(成功= 1表示跳过一行)。 The goal is to skip the following line if authentication is successful: 目标是如果身份验证成功,则跳过以下行:

auth    requisite           pam_deny.so

As this line denies the user access to privileges. 由于此行拒绝用户访问特权。 So, if you want to use su/sudo, but instead of entering your password you use facial comparison, put this above the line above: 因此,如果要使用su / sudo,而不是使用面部比较而不是输入密码,请将此内容放在上面的行上方:

auth [success=2 default=ignore]     pam_exec.so debug log=/path/to/pamlogs.txt /usr/local/bin/susentry

Make sure you change /path/to/pamlogs.txt to where you want the PAM output to be saved. 确保将/path/to/pamlogs.txt更改为要保存PAM输出的位置。 (This ouput is error output and stdin output from your PAM, your bash script, and your python script) Lets break this down. (此输出是您的PAM,bash脚本和python脚本的错误输出和stdin输出)让我们分解一下。

auth [success=2 default=ignore]

Means "If this program returns success (exit 0), then skip the next 2 lines. (Password prompt line, authentication fail line) 表示“如果此程序返回成功(退出0),则跳过接下来的2行。(密码提示行,身份验证失败行)

pam_exec.so debug log=/path/to/pamlogs.txt

This part says "use pam_exec to execute the bash script, and send all the error logs/stdin logs to /path/to/pamlogs.txt 这部分说“使用pam_exec执行bash脚本,并将所有错误日志/ stdin日志发送到/path/to/pamlogs.txt

/usr/local/bin/susentry

This part is the location of the bash script. 这部分是bash脚本的位置。 This is what PAM exec runs and waits for an exit code for. 这就是PAM exec运行并等待退出代码的地方。

If the facial recognition script fails it should fall back to asking for a password. 如果面部识别脚本失败,则应退回要求输入密码。 Please note that you need to be careful when editing /etc/pam.d/common-auth as you can break your sudo. 请注意,在编辑/etc/pam.d/common-auth时需要小心,因为这样会破坏sudo。 You may want to open a new terminal with root privileges while you mess with this stuff so you can revert back the changes. 在您弄乱这些东西时,您可能希望使用root特权打开一个新终端,以便可以还原所做的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM