User avatar
liudr
Posts: 624
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Auto log in on serial port terminal

Fri Feb 05, 2016 9:56 pm

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.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
liudr
Posts: 624
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Auto log in on serial port terminal

Sun Feb 07, 2016 12:33 am

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/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
          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.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
AndyD
Posts: 2320
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Auto log in on serial port terminal

Sun Feb 07, 2016 4:42 am

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/serial-getty@.service /etc/systemd/system/serial-getty@ttyAMA0.service
sudo nano /etc/systemd/system/serial-getty@ttyAMA0.service
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/serial-getty@ttyAMA0.service /etc/systemd/system/getty.target.wants/
sudo systemctl daemon-reload
sudo systemctl start serial-getty@ttyAMA0.service
[/s]
Porbably better to do:-

Code: Select all

sudo systemctl enable serial-getty@ttyAMA0.service
sudo systemctl start serial-getty@ttyAMA0.service
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.
Last edited by AndyD on Sun Feb 07, 2016 6:11 am, edited 1 time in total.

User avatar
liudr
Posts: 624
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Auto log in on serial port terminal

Sun Feb 07, 2016 5:42 am

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.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
AndyD
Posts: 2320
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Auto log in on serial port terminal

Sun Feb 07, 2016 6:09 am

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 serial-getty@ttyAMA0.service

User avatar
liudr
Posts: 624
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Auto log in on serial port terminal

Sun Feb 07, 2016 6:45 am

Thanks. I restarted, halted, powered down. I got auto login after power up.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

Return to “Beginners”

Who is online

Users browsing this forum: Darranking, pageauc and 66 guests