16.04中的pamusb身份validation

有没有机会在Ubuntu 16.04上通过USB或SD卡安装Pamusb进行外部认证? 似乎这个LTS版本不再有pamusb了!

如有任何替代方案,请告知或建议。 非常感谢你!

放弃

这不是PAM模块。 它真正做的就是自动输入密码并按Enter键。 因此,当您插入USB记忆棒时,您应该非常小心。 您的密码将输入任何具有焦点的应用程序,然后输入密钥。 如果活动窗口是聊天客户端,那么这可能非常糟糕。 这些脚本按原样提供,在实现之前,您应该添加额外的安全措施。 例如,我实际使用的一个未实现的安全措施是在USB记忆棒上的第一个分区(使用dd)之前将加密密码写入未使用的空间。 也许检查我们是否在登录屏幕上是另一个应该实施的安全措施。 使用此风险需要您自担风险! 通过使用或调整下面提供的任何信息/代码,您将承担保护自己实施的所有责任。

哈克

我遇到了同样的问题并创建了自己的解决方法 。 我在Ubuntu 16.04上使用lightdm(这是默认设置)。 它将输入凭证ANYTIME插入usb“密钥”,因此在屏幕未锁定时插入USB记忆棒时请小心!

我是如何工作的……

当授权使用USB记忆棒进行身份validation时,USB记忆棒中的各种信息将被用作密码,而密码又用于加密密码。 然后将此加密密码存储在计算机上的某个位置。

接下来,编写一个udev规则,监视要添加到系统的USB存储设备。 添加USB存储设备时,设备路径将写入由助手脚本监视的命名管道。

最后,从命名管道读取的帮助程序脚本检查插入的USB是否具有关联的加密密码条目。 如果是,则加密密码将被解密,并在返回键后面的焦点处自动键入。 将助手脚本与udev脚本分开是很重要的,因为udev脚本运行的范围阻止我们根据需要使用xdotool。

脚本

插入要用于登录的USB。将以下脚本复制到空文件并运行*一次: *请注意,此脚本将创建路径/ etc / usbauth,它将在您的系统上安装xdotool。

#!/bin/bash # This is the a script for authorizing USB devices as logon devices # run as root if [ "$(whoami)" != root ]; then sudo $0 $@ exit fi # Install the xdotool if it's not already installed ( [ "$(which xdotool)" == "" ] && apt install -y xdotool ) & encryptedPasswordStorage="/etc/usbauth" # path where encrypted passwords are stored # if path does not exist create it and make sure permissions are set correctly [ ! -d "$encryptedPasswordStorage" ] && mkdir -p "$encryptedPasswordStorage" chown root:root $encryptedPasswordStorage chmod 700 $encryptedPasswordStorage # Get a list of attached USB storage devices usbDevices=$(ls -l /dev/disk/by-uuid/ | grep -oP "/sd[az][0-9]?" | sort | awk '{print "/dev" $1}' | while read part; do [ "$(udevadm info -q all -n $part | grep "E: ID_BUS" | cut -f2 -d=)" == "usb" ] && echo $part; done) # Iterate over this list and display partitions while read device do info="$(udevadm info -q all -n $device)" vendor=$(echo "$info" | grep "E: ID_VENDOR_ID=" | cut -f2 -d=) model=$(echo "$info" | grep "E: ID_MODEL_ID=" | cut -f2 -d=) sn=$(echo "$info" | grep "E: ID_SERIAL_SHORT=" | cut -f2 -d=) uuid=$(echo "$info" | grep "E: ID_FS_UUID=" | cut -f2 -d=) label=$(echo "$info" | grep "E: ID_FS_LABEL=" | cut -f2 -d=) key="$vendor$model$sn$uuid" checksum=$(echo -n "$key" | sha256sum | cut -f1 -d' ') keyList[$[++i]]="$key" # used as an encryption key for encrypting account password labelList[$i]="$label" checksumList[$i]="$checksum" printf "%5s %-9s %-15s %s\n" "[$i]" $device "$label" $sn done<<<"$usbDevices" # Ask user which attached device should be used for authentication echo "" read -p "Enter the number of the device to authorize: " selection read -sp "Enter your login password: " pwd key=${keyList[$selection]} encpwd=$(gpg2 --output - -a -c --passphrase "$key" --batch --cipher-algo AES256 --digest-algo SHA512<<< "$pwd") # Save the encrypted password to the system encPwdFile="$encryptedPasswordStorage/${labelList[$selection]}_${checksumList[$selection]}" echo -e "$encpwd" > "$encPwdFile" chmod 600 "$encPwdFile" echo "" 

*从现在开始,以root或sudo *创建/编辑所有文件


接下来使用以下内容创建文件/etc/usbauth/udev.sh

 #!/bin/bash # This script watches for USB storage devices. As they are plugged in, this script # sends the path of these devices to a named pipe that is watched by our helper # script. # This script is intended to be called by udev. Add the following rule # file path: /etc/udev/rules.d/80-USB.rules # file contents: ACTION=="add",KERNEL=="sd[az]*",RUN+="[path to this script]" encryptedPasswordStorage="/etc/usbauth" # path where encrypted passwords are stored namedPipe="/tmp/usb-auth" # named pipe used for notification of added USB storage devices [ -e "$namedPipe" ] && echo "$DEVNAME" > "$namedPipe" 

我们还需要创建一个udev规则。 使用以下内容创建/etc/udev/rules.d/80-USB.rules。

 ACTION=="add",KERNEL=="sd[az]*",RUN+="/etc/usbauth/udev.sh" 

现在,使用以下内容创建最后一个文件/etc/usbauth/lightdm.sh。

 #!/bin/sh # this is the helper script that reads devices that are added and automates typing # the password if an authorized stick is plugged in. ( encryptedPasswordStorage="/etc/usbauth" # path where encrypted passwords are stored namedPipe="/tmp/usb-auth" # named pipe used for notification of added USB storage devices rm "$namedPipe"; mkfifo "$namedPipe" # create the named pipe while true;do # this infinite loop helps to ensure that we're always watching for the next device while read device # when a device is read ... do # gather information about the device that was read info="$(udevadm info -q all -n $device)" vendor=$(echo "$info" | grep "E: ID_VENDOR_ID=" | cut -f2 -d=) model=$(echo "$info" | grep "E: ID_MODEL_ID=" | cut -f2 -d=) sn=$(echo "$info" | grep "E: ID_SERIAL_SHORT=" | cut -f2 -d=) uuid=$(echo "$info" | grep "E: ID_FS_UUID=" | cut -f2 -d=) key="$vendor$model$sn$uuid" checksum=$(echo -n "$key" | sha256sum | cut -f1 -d' ') # check to see if this device has an associted encrypted password file encpwdFile="$(find $encryptedPasswordStorage -type f | grep "$checksum")" echo "$key:checksum --> $encpwdFile" > /tmp/encfile # if it does, decrypt the password, type it on the screen and press [Enter] if [ -e "$encpwdFile" ]; then pwd=$(gpg2 -a -d --passphrase "$key" --batch --output - < $encpwdFile) echo "$pwd" > /tmp/pwd xdotool type "$pwd" sleep .5 xdotool key Return fi done < "$namedPipe" done ) & 

当lightdm启动时,必须调用此脚本。 为此,请编辑/usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf。 在[Seat:*]添加

 greeter-setup-script=/etc/usbauth/lightdm.sh 

例如,我的/usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf文件看起来像

 [Seat:*] greeter-session=unity-greeter greeter-setup-script=/etc/usbauth/lightdm.sh 

我还没有创建用于管理已添加的USB设备的脚本,但您会发现所有这些都列在/ etc / usbauth中。 此文件夹中的每个加密密码文件都以分区标签名称后跟下划线和用于加密密码的密钥的sha256哈希开头。 简单地删除加密的密码文件就足以将USB作为认证设备移除。

请注意,如果您重新格式化USB存储设备,UUID将会更改,您将无法再次使用该设备登录,直​​到您再次将其添加为关键字,只需重新运行提供的第一个脚本即可在这篇文章中。 我已经合并了UUID,因为现在大量来自中国的廉价存储设备没有配置序列号。 此外,当您使用SD卡时,值得注意的是,您看到的序列号实际上来自大多数系统上的SD卡读卡器。 因此,如果您使用SD卡,即使SD卡本身的序列号实际上不同,您安装的每张SD卡的序列号也是相同的。