如何从命令行输入lightdm登录界面?
我有一台配有加密主页的大型硬盘驱动器。 碰巧的是,同一台计算机也适用于我家的主要媒体中心。 每次我的孩子想要看电影时,我都必须将其打开,然后将键盘与其物理连接,并输入密码。
我希望能够远程做到这一点。
当然我也有对计算机的root访问权限。
我不愿意使用自动登录创建另一个用户名,因为大多数媒体文件都是加密的,我希望它们保持这种状态。
export DISPLAY=0:
和source discover_session_bus_addres.sh
以及用于键入锁定屏幕的xdotool type my_secret_password
的正常组合在lightm
上lightm
。
这是一个在Ubuntu 16.04下使用lightdm
:
- 让自己成为
root
用户可以访问lightdm的.Xauthority
,它位于/var/lib/lightdm/.Xauthority
下。 将它复制到您可以读取的位置并删除root权限,或者只是保留root权限。 - 将
XAUTHORITY
设置为指向该文件(例如,export XAUTHORITY=/var/lib/lightdm/.Xauthority
) - 将
DISPLAY
设置为活动显示(export DISPLAY=:0
) -
xdotool
现在应该工作了。 尝试xdotool type "My super secret password" xdotool key Return
这是我正在使用的解决方法。 它是丑陋和粗鲁的,但如果自动登录选项可行的话,这种方法也适用于Wayland和GDM(Ubuntu 17.10)。
#!/bin/bash # NAME: lightdm-auto-login main() { # If the file '/etc/lightdm/lightdm.conf' exists create a backup copy [[ -f /etc/lightdm/lightdm.conf ]] && mv /etc/lightdm/lightdm.conf{,.bak} # Create autologin configuration for the current $USER = $1 echo -e "[Seat:*]\nautologin-user=$1" > /etc/lightdm/lightdm.conf # Restart 'lightdm' while autologin option is enabled systemctl restart lightdm.service # Wait for a moment to complete the login process and remove the conf file sleep 30 && rm /etc/lightdm/lightdm.conf # Restore the backup if exists [[ -f /etc/lightdm/lightdm.conf.bak ]] && mv /etc/lightdm/lightdm.conf{.bak,} } # Execute the 'main()' function with root privileges in the background 'sudo -b' # Pass the curent $USER as arg (https://unix.stackexchange.com/a/269080/201297) sudo -b bash -c "$(declare -f main); main $USER"
-
该脚本应作为普通用户(属于sudoers组)执行。
-
该脚本将创建文件
/etc/lightdm/lightdm.conf
的备份副本。 然后它将生成一个带有自动登录选项的新配置文件,为当前用户启用。 此时,lightdm
将重新启动,用户将通过自动登录选项登录。 最后,将删除自定义配置,并恢复配置文件的原始状态。 -
如果正在使用GDM:要重新启动的服务是
gdm3.service
,应该更改的配置文件是/etc/gdm3/custom.conf
。
这适用于我(来自ssh,与lightdm):
$ XAUTHORITY=/var/lib/lightdm/.Xauthority DISPLAY=:0.0 sudo sh -c 'xdotool type "My Password" && xdotool key Return'