AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 909151
Accepted
UTF-8
UTF-8
Asked: 2017-04-27 06:05:32 +0800 CST2017-04-27 06:05:32 +0800 CST 2017-04-27 06:05:32 +0800 CST

仅在暂停 10 分钟后从暂停唤醒时需要密码

  • 772

我通常希望我的笔记本电脑在暂停时被锁定,而不是在我刚刚暂停时锁定,因为有一个用例,在我的笔记本电脑从暂停中醒来后输入我的密码非常麻烦。一个好的折衷方案是仅在笔记本电脑在 10 分钟前被挂起时才需要登录密码。我该怎么做呢?

我使用带有 Unity 的 Ubuntu 16.04。

16.04
  • 3 3 个回答
  • 2155 Views

3 个回答

  • Voted
  1. Best Answer
    Ravexina
    2017-06-16T04:22:13+08:002017-06-16T04:22:13+08:00

    在 中创建一个文件/lib/systemd/system-sleep/,命名为 eg: lightdm:

    sudo touch /lib/systemd/system-sleep/lightdm
    

    使该文件可执行:

    sudo chmod +x /lib/systemd/system-sleep/lightdm
    

    每次您“暂停”或“恢复”您的 Ubuntu 时,都会运行此脚本。

    使用您想要的文本编辑器打开它,例如:sudo nano /lib/systemd/system-sleep/lightdm,然后将此行粘贴到其中,然后保存:

    #!/bin/sh
    set -e
    
    case "$1" in
       pre)
    
        #Store current timestamp (while suspending)
        /bin/echo "$(date +%s)" > /tmp/_suspend 
        ;;
    
       post)
          #Compute old and current timestamp
          oldts="$(cat /tmp/_suspend)"
          ts="$(date +%s)"
    
          #Prompt for password if suspended > 10 minutes
          if [ $((ts-oldts)) -ge 600 ];
           then
             export XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
             /usr/bin/dm-tool lock
          fi
    
          /bin/rm /tmp/_suspend
       ;;
    esac
    

    它能做什么?

    当您将 Ubuntu 置于“睡眠”模式时,此脚本将保存当前时间戳,然后在恢复系统时,它将检查旧时间戳与当前时间戳,如果差异超过“600”秒(10 分钟),它将显示你“lightdm”锁屏,否则它什么也不做。

    最后一步:

    打开“系统设置”->“亮度和锁定”。从挂起唤醒后禁用询问密码,因为我们将处理锁定屏幕留给脚本。

    在此处输入图像描述

    重启或关机后,您仍然需要输入密码。

    • 7
  2. lemonsqueeze
    2017-06-16T04:14:11+08:002017-06-16T04:14:11+08:00

    /lib/systemd/system-sleep/如果系统暂停了很短的时间,请添加一个脚本来解锁您的会话:

    cd /lib/systemd/system-sleep/
    sudo touch     unlock_early_suspend
    sudo chmod 755 unlock_early_suspend
    sudo -H gedit     unlock_early_suspend
    

    有了这个内容:

    #!/bin/bash
    # Don't ask for password on resume if computer has been suspended for a short time
    
    # Max duration of unlocked suspend (seconds)
    SUSPEND_GRACE_TIME=600
    
    file_time()      {  stat --format="%Y" "$1";  }
    
    unlock_session()
    {
        # Ubuntu 16.04
        sleep 1; loginctl unlock-sessions
    }
    
    # Only interested in suspend/resume events here. For hibernate etc tweak this
    if [ "$2" != "suspend" ]; then  exit 0;  fi
    
    # Suspend
    if [ "$1" = "pre" ]; then  touch /tmp/last_suspend;  fi
    
    # Resume
    if [ "$1" = "post" ]; then
        touch /tmp/last_resume
        last_suspend=`file_time /tmp/last_suspend`
        last_resume=`file_time /tmp/last_resume`
        suspend_time=$[$last_resume - $last_suspend]
    
        if [ "$suspend_time" -le $SUSPEND_GRACE_TIME ]; then
            unlock_session
        fi
    fi
    
    • 0
  3. BJsgoodlife
    2017-06-16T02:50:54+08:002017-06-16T02:50:54+08:00

    我可以帮你解决这个问题。首先,进入设置。选择此设置:

    亮度_&锁定

    将有一个下拉菜单显示屏幕关闭。

    Screen_Turns_Off

    单击下拉菜单后,更改两个设置,使其如下所示:

    Lock_Screen

    • -2

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve