Suppose auto-login to a session is active in Ubuntu. So there will not be an opportunity to select a session (e.g gnome, unity, kde, etc). But if the environment is corrupted there is no way to escape except command line.

Is there a way to disable auto-login without relying on GUI session

  • I do not know what implies that I use lightdm so that it is edited to lightdm. I use kdm. Oct 6 '14 at 21:56
  • 1
    You did not specify that you use KDM, so that usually means you use the default, lightdm. You should edit the question to add that essential information and then we can get the answers updated.
    – Seth
    Nov 8 '14 at 1:02

To stop lightdm from automatically logging in user bob, edit /etc/lightdm/lightdm.conf and change the line




(the = will be the line's last character)

  • I don't know how to edit using command line. Oct 3 '14 at 15:43
  • What editors do you know? There may be a command-line equivalent. Oct 3 '14 at 15:49
  • 2
    @MinimusHeximus just run nano /etc/lightdm/lightdm.conf that's a very simple to use text editor.
    – terdon
    Oct 3 '14 at 16:31

You can use sed to do it automatically:

sudo sed -i.backup -e 's/autologin-user=\(.*\)/autologin-user=/ /etc/lightdm/lightdm.conf  

This will change the first occurrence of autologin-user=someUser with autologin-user= (replace someUser with whatever user was set to auto login). It will also create a backup of the original file named lightdm.conf.backup.

Or you could simply delete the line completely:

sudo sed -i.backup '/autologin-user=/d' /etc/lightdm/lightdm.conf

I tested both methods on a fresh 12.04.5 VM and it worked just fine.


Press Ctrl + Alt + F3 and

  1. Login
  2. sudo service "name of login manager" stop

Usually this service is either gdm or lightdm.

  • this will stop gdm, etc. Will it disable auto-login when compter is restarted? Oct 3 '14 at 16:05
  • No you need to stop gdm then reconfigure it then restart, see Disable Autologin
    – eyoung100
    Oct 3 '14 at 16:07
  • Why was this voted down?? just curious
    – eyoung100
    Oct 3 '14 at 16:46
  • Your answer is wrong, it doesn't answer the question. You are just stopping the display manager, not disabling auto-login.
    – Seth
    Oct 3 '14 at 17:09
  • But look at the comment above yours. I suppose I could include this...
    – eyoung100
    Oct 3 '14 at 17:13

If you're using lightdm for logging, but have no GUI, you may run the following:

sudo nano /etc/lightdm/lightdm.conf

You will see a row autologin-user=username, you may comment it with # or simply delete the username statement.

Afterwards, in command line run sudo service lightdm restart or simply restart your PC.

  • 1
    gksudo needs the GUI (GTK to be more precise), which OP shouldn't be able to use.
    – Braiam
    Oct 3 '14 at 16:42
  • 1
    As does gedit itself.
    – terdon
    Oct 3 '14 at 16:43
  • Sorry, missed that. Fixed answer Oct 4 '14 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.