从 U 盘(随身碟)锁定和解锁

Pra*_*hal 15 unlock usb lock

是否有任何程序可以使用闪存驱动器锁定和解锁我的 Ubuntu 机器?

例如,当我取出U盘时,计算机会自动锁定,而当我插入U盘时,计算机会自动解锁。

先感谢您。

Fr0*_*Fyr 10

I know it's a terribly late answer, just thought it might help future readers. I posted the answer at Locking with USB drive

Well, a module called PAM (Pluggable Authentication module) can be customized to achieve your need. A beautiful article is available on linuxconfig describing this in detail.

The steps are:

  1. Install PAM

    $ sudo apt-get install pamusb-tools libpam-usb
    
    Run Code Online (Sandbox Code Playgroud)
  2. Add USB device to PAM config

    $ sudo pamusb-conf --add-device <my-usb-stick>
    
    Run Code Online (Sandbox Code Playgroud)
  3. Select your volume and "Y" to save

  4. Define user for PAM auth

    $ sudo pamusb-conf --add-user <ubuntu-user>
    
    Run Code Online (Sandbox Code Playgroud)
  5. Select and "Y" to save

  6. Configure PAM

    $ sudo gedit /etc/pam.d/common-auth
    
    Run Code Online (Sandbox Code Playgroud)
  7. Add the line below and save

    auth    sufficient      pam_usb.so
    
    Run Code Online (Sandbox Code Playgroud)
  8. Test the PAM auth

    $ su ubuntu-user
    
    Run Code Online (Sandbox Code Playgroud)
  9. Lock when disconnected

    $ sudo gedit /etc/pamusb.conf
    
    Run Code Online (Sandbox Code Playgroud)
  10. Modify the block "user" block to look like:

    <user id="ubuntu-user"> 
          <device> 
                  my-usb-stick 
          </device> 
          <agent event="lock">gnome-screensaver-command -l</agent> 
          <agent event="unlock">gnome-screensaver-command -d</agent> 
     </user>*
    
    Run Code Online (Sandbox Code Playgroud)


use*_*own 6

/etc/udev/rules.d/
Run Code Online (Sandbox Code Playgroud)

你可以写一个脚本

SUBSYSTEM=="usb", SYSFS{idProduct}=="PPPP", SYSFS{idVendor}=="VVVV", RUN+="/usr/sbin/usb-locking"
Run Code Online (Sandbox Code Playgroud)

其中,PPPP 和 VVVV 是您可以使用lsusb.

每个相同的产品都会匹配,但 USB 锁定可以安装设备,并查看驱动器本身以进一步合法化 - 一些文件,其中的一些字节码,日期......

当然,如果其他人可以使用棍子,它很容易受到攻击。

脚本可以每分钟进一步查看棒是否仍然安装,如果没有则锁定。

  • 您的规则应该有 ACTION==add。还有,你为什么要每分钟都看棍子是否在那里?只要在操作杆消失时触发 ACTION==remove 并锁定屏幕。您还应该将棒的序列号和分区的 UUID 添加到规则中。 (2认同)