Page 1 of 1

Auto log in on serial port terminal

Posted: Fri Feb 05, 2016 9:56 pm
by liudr
I am just too linux-noob to figure this out. I am not always using GUI and hate to keep switching cables and keyboard/mouse to go between pi and main computer. So I started exploring logging in with the serial port. It's great! It's fast and I can run python programs I wrote and monitor its progress.

So just curious, can I have auto log in on the serial port terminal? I know the new jessie image does auto log in with GUI so hopefully it's just easy to achieve.

What about starting a python script once logged in? Do I just add it to the end of my .bashrc? OK, confirmed this.

Re: Auto log in on serial port terminal

Posted: Sun Feb 07, 2016 12:33 am
by liudr
Found some references online that indicates that I should change raspi-config:

Code: Select all

      B2*)
        if [ -e /etc/init.d/lightdm ]; then
          if [ $SYSTEMD -eq 1 ]; then
            systemctl set-default multi-user.target
            ln -fs /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
          else
            update-rc.d lightdm disable 2
            sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
          fi
        fi
        ;;
This is for the normal console, not for serial console. I wonder if I should duplicate a line with lin -fs ... just replacing tty1 with ttyAMA0.

I'm a noob. Not sure what to do really.

Re: Auto log in on serial port terminal

Posted: Sun Feb 07, 2016 4:42 am
by AndyD
Can I assume you are using Raspbian Jessie? If so, from reading systemd for Administrators, Part XVI you can do the following:-

Code: Select all

sudo cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]
sudo nano /etc/systemd/system/[email protected]
Change the line

Code: Select all

ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM
to

Code: Select all

ExecStart=-/sbin/agetty --autologin pi --noclear --keep-baud 115200,38400,9600 %I $TERM

Code: Select all

sudo ln -s /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/
sudo systemctl daemon-reload
sudo systemctl start [email protected]
[/s]
Porbably better to do:-

Code: Select all

sudo systemctl enable [email protected]
sudo systemctl start [email protected]
Note: I haven't tested this, but I think this is correct.

The issue is that the serial getty service is created using the systemd-getty-generator. To change the defaults, in this case autologin, you need to create a specific service file for the serial device.

Re: Auto log in on serial port terminal

Posted: Sun Feb 07, 2016 5:42 am
by liudr
Thank you so much! Yes, I'm using jessie.

I followed your direction to copy the service and added the auto login. I didn't do the ln command but upon restarting, it is already doing auto login. So what is the purpose of creating the link? The reference doesn't say why there needs to be a link.

Right now, the getty.target.wants/ folder only has tty1 in it.

Re: Auto log in on serial port terminal

Posted: Sun Feb 07, 2016 6:09 am
by AndyD
liudr wrote:I didn't do the ln command but upon restarting, it is already doing auto login. So what is the purpose of creating the link? The reference doesn't say why there needs to be a link.
From my understanding. If you have started the service, that works for now. But, when you reboot the system, the service will only load if it is enabled. The ln is probably the same as

Code: Select all

sudo systemctl enable [email protected]

Re: Auto log in on serial port terminal

Posted: Sun Feb 07, 2016 6:45 am
by liudr
Thanks. I restarted, halted, powered down. I got auto login after power up.