I'm a newbie to Ubuntu (indeed any Linux distro), forgive me for any poorly connected dots!
I recently encountered this too, seemed odd as I hadn't changed anything (intentionally). I'd been away for a few minutes and had to unlock the user again. It wouldn't work but it had less than 10 minutes before. I tried it a few times and was confident I was using the correct password.
I jumped into a guest account to check out AskUbuntu and found your question. I was about to give prakharsingh95's answer a go but for sanity's sake I tried typing the password as visible text and it seemed fine. I then tried to unlock again and it allowed me in.
I was a little confused but then I noticed my default language had changed from EN1 to EN2. This was the problem because of one of the characters in my password maps differently between the keyboard layouts. I'm guessing that using the guest account reset the language before I attempted to unlock again. I did a little more reading and came across this with a few answers Keyboard layout switches to English each time I reboot. For now I'm attempting the most popular answer but it also helped me come across what I believe was the culprit in my case. Super+Space will change to the next layout. I probably inadvertently did this after first logging on.
Hopefully this will be useful to anyone else in the same situation.
The other question that muru has linked in the comments ( TTY[1-6]: Lock screen after delay (like a screensaver) ) offers us the tool to locking the tty , vlock
. At the simplest level , you can combine vlock -a
with pm-suspend
into a .bashrc
function or a script. Here's mine:
$ cat lockTTY.sh
#!/bin/bash
(sleep 3; sudo pm-suspend) &
vlock -a
What is happening here ? Basically we're launching pm-suspend
with delay in subshell , in background. Meanwhile we use vlock -a
to lock all the ttys. After 3 seconds, the laptop suspends.
The catch here however is the sudo pm-suspend
part. You have to prevent sudo
from asking you password for pm-suspend
. In order to do that, we add the following line at the end of /etc/sudosers
file
$USERNAME ALL = NOPASSWD: /usr/sbin/pm-suspend
Of course , replace $USERNAME
with your actual username. You might call sudo visudo
to open that file with your default text editor set in /etc/alternatives/editor
, just to be safe, but any editor called with proper permissions will do.
What does this script allows us to do ? Suspend and lock with processes still running. vlock -a
has big advantage in preventing switching to other consoles, so it's not just one console being locked, but all of them - you cannot just switch to another tty if one is locked.
You could also suspend first and lock second, i.e. call pm-suspend
first and vlock -a
second. But that means upon resume there is possibility someome may see your screen for a fraction of a second before vlock
kicks in.
What would be the simple and dirty solution in case you don't trust vlock
and don't want to install it ? Create a script /etc/pm/sleep.d/10_lockTTY
with the following contents:
#!/bin/bash
case "${1}" in
hibernate|sleep)
;;
resume|thaw)
for NUM in $(seq 1 6); do service tty$NUM restart; done
;;
esac
This will reset all ttys upon return from suspend, but mind - any processes you had there will be killed.
Best Answer
First, let's try your account from the console. WRITE DOWN THESE DIRECTIONS BEFORE BEGINNING - you won't be able to read from here once you start.
Press Ctrl-Alt-F1. This will bring you to a text only console. Log in with your username and password. Once you've accomplished that, do
sudo -s
, and give it your password again. After doing that, press Press Ctrl-Alt-F7. This will bring you back to the usual graphical screen you're used to.Were you able to log in at the shell? Were you able to successfully sudo to root (did the prompt change to
root@yourmachine:~#
)?OK. You've done this, and you cannot log in at all. So, you will need to reset the password for your username. First, try doing CtrlAltT to bring up the Terminal. Type in
passwd
and hit enter. Will it allow you to change your password? If so, you should be good. If not, you'll need to boot to single user mode in order to reset your password.If you could not change your password, let's get into Recovery Mode. Reboot the system, and at the GNU GRUB menu, press down arrow, and select (recovery mode) as shown here:
Now, drop to root shell prompt:
OK, now you'll need to remount your root filesystem read-write, and then you can change your password:
NOTE: you may be confused about what your actual username is - it's not necessarily the same thing you see at the Ubuntu login prompt! For example, I see "Jim Salter" when I log into my workstation, but my actual username is something completely different and much shorter. If your system tells you there is no such user, you can do
less /etc/passwd
to look for your actual account name - it should be towards the end of the file. Mine looks something like this:Once you've successfully changed the password on your account,
exit
, "resume normal boot", and log in as normal, with shiny new (working!) password.