要求用户输入密码才能运行程序的最简洁方法?

要求用户输入密码才能运行程序的最简洁方法?

要求用户输入密码才能运行特定程序而不使用第三方应用程序的最干净的方法是什么?例如,如果我firefox从终端键入以启动它,它将提示输入密码,并且仅在输入正确的密码时才运行它。类似的东西可能会影响用户权限的使用。

答案1

创建exampleuser并为其设置密码

然后将firefox权限更改为700并将 firefore 更改ownexampleruser;此后您可以仅运行 Firefoxrootexampleuser使用sudosu命令。

例如:

sudo useradd exampleuser
sudo passwd exampleuser 
sudo chown exampleuser:exampleuser ../firefox 
sudo chmod 700 ../firefox

测试:

$ ../firefox
bash: ../firefox: Permission denied
$ su - exampleuser -c ../firefox
Password:  #<-- type exampleuser password

或使用 root 用户运行:

$ sudo ../firefox
[sudo] password for username:  #<-type root password

答案2

在此输入图像描述

使用此脚本在对话框中询问密码,然后启动应用程序。如果密码正确,则会解密应用程序的完整路径以运行它。

在使用该脚本之前,请尝试在计算机上隐藏您的应用程序,然后使用此命令加密您的应用程序的完整路径。它会询问您的密码,然后以 Base64 进行加密和编码,即完整路径: echo -n "/Path/To/Your/Application" | openssl enc -aes256 -a -pbkdf2

该脚本需要 yad 显示对话框: sudo apt install yad

#!/bin/bash
#
# Require yad:
# $ sudo apt install yad
#
# Before use it, use these command to get the full path of your application, encrypted and coded in base64, with your password:
# $ echo -n "/Path/To/Your/Application" | openssl enc -aes256 -a -pbkdf2

function main
{
password=$(yad --text-align=center --text="Password" --entry --entry-text="" --hide-text --fixed --title="" --button=OK)

data="xxx" # replace xxx by the full path of your app encrypted and coded in base64 with the upper command

MyApp=$(echo "$data" | openssl enc -aes256 -d -a -pbkdf2 -pass pass:"$password")
$password=""

# test if file exist
if [ -a $MyApp ]
then
    $MyApp # run your application
    exit 0
else
    notify-send "Incorrect" "$x/3"
fi
}

# limit try
x=1
while [ $x -le 3 ]
do
  main
  x=$(( $x + 1 ))
done

exit 0

相关内容