Author Topic: CLI Edition autologin  (Read 1259 times)

Offline jjmg

  • Newbie
  • *
  • Posts: 3
CLI Edition autologin
« on: April 21, 2015, 01:05:54 pm »
Hello,

I am testing SparkyLinux 3.6 CLI i586 non-pae  and trying to configure an automatic login. I tried several different solutions available in the internet without success. All these solutions I found in the internet, changes the getty configuration in the inittab file, using agetty, mingetty or rungetty. Nothing works and the system always asks for the username and password.
Does anybody can help me ?

Regards,

JJ

Offline pavroo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1467
    • SparkyLinux
Re: CLI Edition autologin
« Reply #1 on: April 21, 2015, 04:52:49 pm »
Sparky uses lightdm as default (and kdm in kde spin now) so check here as the first step:
http://sparkylinux.org/forum/index.php/topic,2617.msg3948.html
Nothing is easy as it looks.

Offline jjmg

  • Newbie
  • *
  • Posts: 3
Re: CLI Edition autologin
« Reply #2 on: April 21, 2015, 05:21:09 pm »
Ok, but I am using the CLI Edition and there is no lightdm or kdm.

Offline pavroo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1467
    • SparkyLinux
Re: CLI Edition autologin
« Reply #3 on: April 21, 2015, 05:35:49 pm »
I see, just text based environment.
I never try to do so yet, I always log in.
Nothing is easy as it looks.

Offline way12go

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 476
  • Existence is all about what matters & what doesn't
Re: CLI Edition autologin
« Reply #4 on: April 22, 2015, 05:43:17 am »
Quote
http://littlesvr.ca/linux-stuff/articles/autologinconsole/autologinconsole.php

Log in automatically to a console when Linux boots

Posted by: Andrew Smith
Poster contact info: andrew-smith at mail ru
Author: Various
Originally published: http://www.linuxquestions.org/questions/t374338.html
Software: Linux All, agetty

Here's a scenario: someone wants a Linux machine (terminal-only, no GUI) to log in automatically to a console and execute a command.

In this guide I use Slackware (doesn't matter which version) but the same should work for any other distribution. you need to do a bit of work to set it up but it's all described here.

First edit the file /etc/login.defs and uncomment the following line (remove the '#' in front):
NO_PASSWORD_CONSOLE tty1:tty2:tty3:tty4:tty5:tty6

You have to do that so it doesn't ask for a password once you log in.

Second, edit /etc/inittab. This file is a bit compicated so it helps if you're familiar with it a little, but if you're not just work on the following line:
c1:12345:respawn:/sbin/agetty 38400 tty1 linux

You want to tell the agetty program to execute an auto login program (we will write this below). Replace the line above with the follwing:
c1:12345:respawn:/sbin/agetty -n -l /usr/sbin/autologin 38400 tty1 linux

The /usr/sbin/autologin program doesn't come with your system, you have to write it and compile it yourself, but it's pretty easy. First create an empty text file and add the following contents to it:
int main()
{
  execlp( "login", "login", "-f", "andrew", 0);
}

Replace andrew with the name of the user you want to log in automatically and save the file as autologin.c.

Then compile the program like this (you have to be root for that to work):
cc autologin.c -o /usr/sbin/autologin

And that's it. When your machine finishes booting it will execute the autologin program which will log in as the user you specified in autologin.c and because you edited /etc/login.defs it won't ask for a password.

Now to execute a program after it logs in just edit .bash_profile in the user's home directory (create the file if it doesn't exist) and append the command you want to run at the end of that file, for example this is my .bash_profile, all it does is run pico:
pico

Enjoy.
Existence is all about what matters and what doesn't. - Sagar Gorijala.

Offline way12go

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 476
  • Existence is all about what matters & what doesn't
Re: CLI Edition autologin
« Reply #5 on: April 22, 2015, 05:44:24 am »
Quote
http://blog.shvetsov.com/2010/09/auto-login-ubuntu-user-from-cli.html

There are a lot of recipes out there on how to automatically login into a given Linux user's account on start up, but most of them rely on some sort of graphical environment or display manager to be present. It took me quite a bit of digging to find a way to auto login in Ubuntu with nothing but CLI. I'm sure others will find this tip useful.

To auto login user "bob" on first console terminal (tty1) edit file /etc/init/tty1.conf and replace last line:

exec /sbin/getty -8 38400 tty1
with this:

exec /bin/login -f bob < /dev/tty1 > /dev/tty1 2>&1
and Robert's your father's brother, next time you boot your machine bob will automatically log into his account on tty1.
Existence is all about what matters and what doesn't. - Sagar Gorijala.

Offline jjmg

  • Newbie
  • *
  • Posts: 3
Re: CLI Edition autologin
« Reply #6 on: April 22, 2015, 10:52:24 am »
I searched for solutions in the internet before asking the forum. I found many solutions like the above but none worked with Sparky CLI Edition.
The NO_PASSWORD_CONSOLE is not recognized by Sparky Linux. I also tried the small C program with no success. I am using the solution that replaces agetty by login -f with another distribution (ttylinux) but it doesn't work with Sparky CLI as well.

Offline way12go

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 476
  • Existence is all about what matters & what doesn't
Re: CLI Edition autologin
« Reply #7 on: July 27, 2016, 03:46:41 am »
http://littlesvr.ca/linux-stuff/articles/autologinconsole/autologinconsole.php

Spoiler (click here to view)
Log in automatically to a console when Linux boots

Posted by: Andrew Smith
Poster contact info: andrew-smith at mail ru
Author: Various
Originally published: http://www.linuxquestions.org/questions/t374338.html
Software: Linux All, agetty

Here's a scenario: someone wants a Linux machine (terminal-only, no GUI) to log in automatically to a console and execute a command.

In this guide I use Slackware (doesn't matter which version) but the same should work for any other distribution. you need to do a bit of work to set it up but it's all described here.

First edit the file /etc/login.defs and uncomment the following line (remove the '#' in front):
NO_PASSWORD_CONSOLE tty1:tty2:tty3:tty4:tty5:tty6

You have to do that so it doesn't ask for a password once you log in.

Second, edit /etc/inittab. This file is a bit compicated so it helps if you're familiar with it a little, but if you're not just work on the following line:
c1:12345:respawn:/sbin/agetty 38400 tty1 linux

You want to tell the agetty program to execute an auto login program (we will write this below). Replace the line above with the follwing:
c1:12345:respawn:/sbin/agetty -n -l /usr/sbin/autologin 38400 tty1 linux

The /usr/sbin/autologin program doesn't come with your system, you have to write it and compile it yourself, but it's pretty easy. First create an empty text file and add the following contents to it:
int main()
{
  execlp( "login", "login", "-f", "andrew", 0);
}

Replace andrew with the name of the user you want to log in automatically and save the file as autologin.c.

Then compile the program like this (you have to be root for that to work):
cc autologin.c -o /usr/sbin/autologin

And that's it. When your machine finishes booting it will execute the autologin program which will log in as the user you specified in autologin.c and because you edited /etc/login.defs it won't ask for a password.

Now to execute a program after it logs in just edit .bash_profile in the user's home directory (create the file if it doesn't exist) and append the command you want to run at the end of that file, for example this is my .bash_profile, all it does is run pico:
pico

Enjoy.

Existence is all about what matters and what doesn't. - Sagar Gorijala.