I'm the only frequent user on a system using gdm, but in the login screens' user list I am not moved upwards (due to most frequent use), and I cannot find a possibility to order the users manually. I confirmed they are not ordered by numeric UID. The same question has been answered here (and here another related one), but for older systems using consolekit, which has been replaced by systemd-logind and AccountsService in the meantime.
3 Answers
The last command lists the past successful logins on the system. This information is stored in the /var/log/wtmp file, and is used by gdm since version 3.17.2 to sort the list of users.
If you delete the /var/log/wtmp file and then reboot, the list of users will default to alphabetical order. After your next login, your user will become the most frequently used so that it will appear on the top of the list.
Note: You will lose the login history of the system if you delete the /var/log/wtmp file. You may want to create a backup of that file.
Tested in Ubuntu Desktop 20.04.3 and 21.04
Building on Alejandro's answer, if you do not want to delete the /var/log/wtmp file, you can run a script that will "stack the deck" to ensure a specific sort order through the use of the login and expect commands.
Here's how you can do it:
Open Terminal (if it's not already open)
(If Required) Install
expect:sudo apt install expectSwitch to the super-user and head to
/rootfor the sake of cleanliness:sudo su cd ~Create a script that will login as a given account. For this example, let's call it
logins.sh(but you can call it whatever you'd like):vi logins.shNote: Feel free to use any text editor. The use of
viin this example is more the result of muscle memory than an explicit recommendation.Paste this into the new file:
#!/usr/bin/expectset timeout 10
set user [lindex $argv 0]
set password [lindex $argv 1]
spawn login $user
expect "Password:"
send "$password\r"
expect "$user@{hostname}:~$"
send "exit\r"
interact
Note: Be sure to replace
{hostname}with the host of your computer.Save the file and exit.
Set the file as executable:
chmod +x logins.shTest it:
./logins.sh nozomi superSecretPassword\!123Note: Unless you share a name with my dog, be sure to change
nozomiwith the proper account name andsuperSecretPassword\!123with the proper password. If your password contains characters that may be misunderstood by bash such as!, be sure to escape them with a\.If everything works, you will see that the specified account is logged into and, after about 8~10 seconds, it is automagically logged out.
Verify this added a record to
/var/log/wtmp:lastYou should see something like this:
$ last nozomi pts/1 Thu Sep 9 00:38 - 00:39 (00:00)Run the script dozens, hundreds, or thousands of times:
for i in {1 .. 999}; do /root/logins.sh nozomi superSecretPassword\!123; doneNote: Be sure to replace
999with the number of times you'd like the script to run. Be aware that the number should be greater than zero and that each run will require about 10 seconds in total to complete. Also be sure to replace the username and password with the account you want to have set at the top.If there are other accounts that you would like near the top, but not at the top, run the command in #8 again, with fewer runs in the
forloop. Be aware that at roughly 6 runs per minute, 1000 runs will require about 2h45m in human time to complete. You may want to run this overnight.(Optional) Consider modifying the script to run for multiple accounts and scheduling it to run daily or weekly.
This has been tested on stock Ubuntu 20.04 LTS and 21.04, but should work with every version of Ubuntu from (at least) 18.04 upwards.
-
Nice trick! Does SSH logins trigger the gdm logic, too? Because they appear in
lastoutput (i.e./var/log/wtmp), so you could instead setup pubkey logins (~/.ssh/authorized_keys) and do the same much simpler withfor i in $(seq 1000); do ssh nozomi@localhost date ; done– azrdev Sep 13 '21 at 08:23 -
1Another one @matigo: Please don't put passwords as command-line parameters, or tell people to do so: They can be read by every other local user in
/proc/$PID/cmdline, and are written to your shell history too – azrdev Sep 13 '21 at 08:25 -
Yes, SSH logins are also visible with
last(along with the source IP). Your suggestion would certainly save a little bit of typing – matigo Sep 13 '21 at 08:25
The reason might be, that your gdm might be configured not to include all users.
This behaviour used to be configured in /etc/gdm3/custom.conf in the [greeter] section (Include=) - this however does not seem to work anymore (see gdm disregards /etc/gdm/custom.conf exclude user list).
It might be that either user azrdev is considered a system-account by GDM3 and therefore not displayed in the user-list at all OR system-accounts are incorrectly classified as non-system accounts and therefore ending at the top of the list.
If that is the case, you can add a file named /var/lib/AccountsService/users/username and change the value of
[User]
SystemAccount=true
to remove that user from the GDM greeter.
- 2,081
- 171
lastand see the output to check what is happening there. Perhaps another user logged in a lot of times in the past and is still on top, or perhaps the/var/log/wtmpfile is locked or not updating for some reason. – Alejandro Sep 08 '21 at 14:14