Unlock screen from command line

5,404

Go to TTY and run the command:

sleep 5; xdotool type <yourpassword>; xdotool key Return

and then go back to the login screen and click in the password box. Wait ~5 secs and your password will be typed and enter will have been pressed.

My pronouns are He / Him

Share:
5,404
kbenoit
Author by

kbenoit

Back in 2000, while studying CS in college, I was not happy with the Micro$oft attitude. So I took a year off and discovered Linux that gave me an interest to return studying CS. So I did search the University that was the most Linux oriented. In my first week, at Sherbrooke University, I was hired to maintain Linux in the Lab. Later I applied for an internship with Karim Yaghmour, the author of Building Embedded Linux Systems, that got me involved in Kernel Development. I used a few distros, my own (LFS) among others, but actually feel happy with using Ubuntu as my main OS, since about 2006.

Updated on September 18, 2022

Comments

  • kbenoit
    kbenoit over 1 year

    I was using virtualbox on a laptop and closed the lid which locked the screen and sleep the computer. Now it came back from sleep, the screen is locked, but I can not type my password. The mouse work, I can set focus in the password box, but typing does nothing.

    I guess the keyboard is held by virtualbox.

    I tried plugin in a keyboard, no luck. I tried killing unity-panel-service --lockscreen-mode, it seems to have a watchdog that restart it.

    I'll find some command line to sleep my vm, but is there anyway to unlock the screen from command line ?

    • kbenoit
      kbenoit over 9 years
      "vboxmanage controlvm <VMName> savestate" -- saves the state of the vm then in my case I have no other work in progress so I just restarted lightdm.
    • Aquarius Power
      Aquarius Power over 9 years
      have you tried to SIGSTOP vbox?
  • kbenoit
    kbenoit over 9 years
    You can normally set your DISPLAY variable to access you X session from a virtual terminal, but to be helpful, there should be a command to tell unity to unlock the screen.
  • sbergeron
    sbergeron over 9 years
    but without accessing a terminal from that specific x session i don't think it's possible
  • kbenoit
    kbenoit over 9 years
    Sounds good, but it refuse my password ???
  • kbenoit
    kbenoit over 9 years
    One should use "read pwd < /dev/stdin", type your password then use $pwd in place of <yourpassword> so that your password is not saved in history or use HISTIGNORE.
  • kbenoit
    kbenoit over 9 years
    xdotool type abcdefghijklmnopqrstuvwxyz ouput qbcdefghijkl~nopqrstuvwxywcq ? But works fine on some other computer. That one was installed in french, the installer set a few things fr_FR instead of fr_CA. This seems to be the problem.
  • kbenoit
    kbenoit over 9 years
    Type ctrl-alt-F1, log in, type "export DISPLAY=:0". This terminal is now the same as a terminal inside you X session, you can start X programs and they will appear in the virtual terminal at ctrl-alt-F7. To ensure you are allowed to access the session, the file $HOME/.Xauthority contains the credentials needed to access a particular X instance.
  • JellicleCat
    JellicleCat over 7 years
    Why does this work when entered on a shell but not when run from a script in /lib/systemd/system-sleep?
  • Tim
    Tim over 7 years
    @JellicleCat I guess because no x screen is attached to systmd?
  • JellicleCat
    JellicleCat over 7 years
    @Tim : thanks. With your guidance, I incorporated this answer to successfully use xdotool on the login screen from system-sleep: stackoverflow.com/a/10721288/507721
  • JellicleCat
    JellicleCat over 7 years
    Additionally, in my script, I needed to run xdotool as my own user, not as root (which matters because system-sleep's scripts run as root.