Advertising

Welcome to SparkyLinux forums
Zapraszamy również na polsko-języczne Forum https://forum.linuxiarze.pl

CLI Edition autologin

Started by jjmg, April 21, 2015, 01:05:54 PM

Previous topic - Next topic

jjmg

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

pavroo

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. Danielle Steel
Join #sparkylinux.org at [url="//irc.libera.chat"]irc.libera.chat[/url]

jjmg

Ok, but I am using the CLI Edition and there is no lightdm or kdm.

pavroo

I see, just text based environment.
I never try to do so yet, I always log in.
Nothing is easy as it looks. Danielle Steel
Join #sparkylinux.org at [url="//irc.libera.chat"]irc.libera.chat[/url]

way12go

Quotehttp://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.
Success gives birth to success? Failure gives birth to failure? - Sagar Gorijala.

way12go

Quotehttp://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.
Success gives birth to success? Failure gives birth to failure? - Sagar Gorijala.

jjmg

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.

way12go

http://littlesvr.ca/linux-stuff/articles/autologinconsole/autologinconsole.php

[spoiler]
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.

[/spoiler]
Success gives birth to success? Failure gives birth to failure? - Sagar Gorijala.

View the most recent posts on the forum