avineshwar
Posts: 5
Joined: Thu Apr 02, 2015 8:27 pm

Autologin not working [SOLVED]

Thu Apr 02, 2015 8:43 pm

Code: Select all

# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

# The default runlevel.
id:2:initdefault:

# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.

l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."

# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop

# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#  <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
# 1:2345:respawn:/sbin/getty --noclear 38400 tty1 
1:2345:respawn:/sbin/getty -a pi 38400 tty1
#  1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1
# 1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 ttyAMA0
# 1:2345:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyAMA0 115200 vt100
# 1:2345:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyAMA0 115200 vt100
# 1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
# T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyUSB0 115200 vt102
#T0:23:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyS0 115200 vt102
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

# Example how to put a getty on a modem line.
#
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3


#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty --autologin pi --noclear 38400 ttyAMA0
# T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyUSB0 115200 vt100
I tried various things to setup an autologin, quite clearly nothing worked yet!
My connection of RPi B+ is using a USB-to-TTL converter (a serial type of connection) and I am using the serial option inside the Putty software to connect my Pi to SSH in my Windows or Linux. Leaving autologin, everything is good and up-to-date so probably any old autologin methods are not working I guess. There are various commented lines in my inittab file. Those are the things I tried but never managed to setup an autologin.
It would be of great assistance if someone could point out things I'm missing and anything where I'm wrong.
I would be happy to provide any required information needed to tackle the situation.

As per the hit-n-trials,
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty --autologin pi --noclear 38400 ttyAMA0
# T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyUSB0 115200 vt100
this part of the inittab file has proved to be crucial because any improper edits in this has affected the entire process of login after the booting and loading of files (which is clearly visible in a ssh terminal) and, even maybe because I'm using a usb-to-ttl (serial connection) for connecting to ssh.


User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 7:30 am

I'm not the guy to answer, but I don't like to see unanswered posts. I'm not clear on what you are trying to do, but I think 'auto login' is separate from 'logging in via ssh'. The first will log you in on tty0; you can check that with a monitor and keyboard directly connected. Using SSH, you're starting another session, and all bets are off. To automate that, you should look into using SSH public/private keys, to avoid having to enter a password.

avineshwar
Posts: 5
Joined: Thu Apr 02, 2015 8:27 pm

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 9:55 am

Douglas6 wrote:I'm not the guy to answer, but I don't like to see unanswered posts. I'm not clear on what you are trying to do, but I think 'auto login' is separate from 'logging in via ssh'. The first will log you in on tty0; you can check that with a monitor and keyboard directly connected. Using SSH, you're starting another session, and all bets are off. To automate that, you should look into using SSH public/private keys, to avoid having to enter a password.
Apparently it would be correct to say that what I am trying to do was auto-login to RPi via SSH without using the public-private key pair method and instead trying to modify the inittab file for that, accordingly. But the auto-login thing is totally different I guess when it comes to SSH. Probably that is not going to work that way ever, ain't so?
& normally, the auto-login should work using the edits in the inittab file, right?

When it comes to connecting the monitor (or some display), is it so that the auto-login will work only if it is through the HDMI port?

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 12:36 pm

You may be confusing serial terminal with SSH. PuTTY supports both, but they are quite different to the Pi.

Serial logins use a dedicated serial cable. A getty process runs on /dev/ttyAMA0 (or /dev/ttyUSBn), which is the device file representing the physical serial port. Normally you send a username and password over the serial line to login, but you can tell getty to autologin instead.

SSH uses Ethernet (or some other network interface). It listens for network connections on TCP port 22, negotiates encryption and authenticates the remote user, and then sets up a "pseudo-terminal" /dev/pts/n. Your shell and programs use this pretend serial port instead of a real one.

You cannot autologin on a psuedo-terminal because you never do send a username and password over one. The pts device is not even created until after a user has connected and authenticated to some network program or graphical interface.

SSH can communicate the username automatically, and it can also use authentication methods like keys that do not require typing a password.
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty --autologin pi --noclear 38400 ttyAMA0
# T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyUSB0 115200 vt100
For autologin on a physical serial port, you only need to add --autologin pi somewhere between getty and the port name. The first attempt above is nearly correct (it will actually work), but it is set for a slower baud rate, so PuTTY would need to be configured differently. The second example requires a non-standard utility /usr/local/bin/autologin. The third example tries to start a root shell (in a way that may still require a password!). If you are using a serial cable to the onboard UART, try:

Code: Select all

T0:23:respawn:/sbin/getty --autologin pi -L ttyAMA0 115200 vt100

avineshwar
Posts: 5
Joined: Thu Apr 02, 2015 8:27 pm

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 3:32 pm

jojopi wrote:You may be confusing serial terminal with SSH. PuTTY supports both, but they are quite different to the Pi.

Serial logins use a dedicated serial cable. A getty process runs on /dev/ttyAMA0 (or /dev/ttyUSBn), which is the device file representing the physical serial port. Normally you send a username and password over the serial line to login, but you can tell getty to autologin instead.

SSH uses Ethernet (or some other network interface). It listens for network connections on TCP port 22, negotiates encryption and authenticates the remote user, and then sets up a "pseudo-terminal" /dev/pts/n. Your shell and programs use this pretend serial port instead of a real one.

You cannot autologin on a psuedo-terminal because you never do send a username and password over one. The pts device is not even created until after a user has connected and authenticated to some network program or graphical interface.

SSH can communicate the username automatically, and it can also use authentication methods like keys that do not require typing a password.
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty --autologin pi --noclear 38400 ttyAMA0
# T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty -l /sbin/sulogin -n -L ttyUSB0 115200 vt100
For autologin on a physical serial port, you only need to add --autologin pi somewhere between getty and the port name. The first attempt above is nearly correct (it will actually work), but it is set for a slower baud rate, so PuTTY would need to be configured differently. The second example requires a non-standard utility /usr/local/bin/autologin. The third example tries to start a root shell (in a way that may still require a password!). If you are using a serial cable to the onboard UART, try:

Code: Select all

T0:23:respawn:/sbin/getty --autologin pi -L ttyAMA0 115200 vt100

I didn't even saw I missed that!

Brother, thanks to you.. ;)
Auto-login to ssh is happening now.

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 8:12 pm

avineshwar wrote:Auto-login to ssh is happening now.
Surely you mean either autologin on serial terminal, or key-based authentication with SSH…

avineshwar
Posts: 5
Joined: Thu Apr 02, 2015 8:27 pm

Re: Autologin not working (Serial connection to SSH using Pu

Fri Apr 03, 2015 8:33 pm

jojopi wrote:
avineshwar wrote:Auto-login to ssh is happening now.
Surely you mean either autologin on serial terminal, or key-based authentication with SSH…
on serial terminal.

sayali
Posts: 2
Joined: Wed Sep 23, 2015 8:26 am

Re: Autologin not working [SOLVED]

Wed Sep 23, 2015 8:32 am

I'm using ssh and Xming server to run Pi on my laptop, i need to run python script after login, in which i succeeded.
I need help for auto login.

I tried editing 1:2345 line, but session keep asking for login...so I felt its not taking any effect..and commented all those 6 lines. I was expecting I need to flash sd card again..but nothing happened and session still asking me for login.
I think those lines won't affect login process.

Please tell which Line taking effect? Where do I make changes?

mariusco
Posts: 17
Joined: Thu Nov 21, 2013 6:53 pm

Re: Autologin not working [SOLVED]

Wed Feb 24, 2016 5:56 pm

Hi,
I have a RPI (miniban).
This method worked flawless before on any board I used, iMX, regular Linux, and
if I remember right earlier RPI's I used a year ago or son.

I tried different options and still over serial is asking for a password.
I tried even the autologin.c

Code: Select all

  #include <unistd.h>

    int main(int argc, char *argv[])
    {
      execlp( "login", "login", "-f", "pi", 0);
      return 0;
    }
and initab

Code: Select all

T0:23:respawn:/sbin/getty -n -l /usr/bin/autologin -L ttyAMA0 115200 vt100
I tried all the options down here.

Code: Select all

[email protected]:~# cat /etc/inittab
#Spawn a getty on Raspberry Pi serial line
# T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# T0:23:respawn:/sbin/getty -L ttyAMA0 --autologin root 115200 vt100
#T0:23:respawn:/sbin/getty -n -l /usr/bin/autologin -L ttyAMA0 115200 vt100
#T0:23:respawn:/sbin/agetty -n -l /usr/bin/autologin -L ttyAMA0 115200 tty1 linux
#T0:23respawn:/sbin/agetty -n -l /usr/sbin/autologin 115200 tty1 linux

T0:23:respawn:/sbin/getty --autologin pi -L ttyAMA0 115200 vt100
and none of them seems to work.

Thank you

mariusco
Posts: 17
Joined: Thu Nov 21, 2013 6:53 pm

Re: Autologin not working [really solved]

Mon Feb 29, 2016 6:59 pm

Autologin user, eg: pi
System OS, RPI, systemd,
1 create autologin binary

Code: Select all

    nano autologin.c
    // type following 8 lines
    #include <unistd.h>
    int main(int argc, char *argv[])
    {
		execlp( "login", "login", "-f", "pi", 0);
		return 0;
    }

// Ctrl+0 to save, then compile-link
 gcc -o autologin autologin.c
sudo cp ./autologin /usr/sbin/autologin
sudo chmod +x /usr/sbin/autologin
2. Create 2 files autologin.conf in following folders.
If your serial interface is different than ttyAMA0 create / rename that folder accordingly.

Code: Select all

/etc/systemd/system/[email protected]/autologin.conf
/etc/systemd/system/[email protected]/autologin.conf
3. Add following content. Change the tty* accordingly to tty device.
To enable auto-login on tty default console terminal

Code: Select all

$ cat [email protected]/autologin.conf
[Service]
ExecStart=
ExecStart=/sbin/agetty -n -l /usr/sbin/autologin -L %I $TERM

To enable auto-login on serial GPIO's serial console, my case ttyAMA0

Code: Select all

$ cat ./[email protected]/autologin. conf
[Service]
ExecStart=
ExecStart=/sbin/agetty -n -l /usr/sbin/autologin -L ttyAMA0 115200 vt102

Return to “Troubleshooting”