cloudbu
Posts: 3
Joined: Thu Dec 28, 2017 12:38 pm

Login via uart without type username and password

Fri Dec 29, 2017 4:05 pm

Hi everyone.
I need send serial command without sending username and password. I tried "Console Autologin" in raspi-config, but still after reboot I have to type username and password.

How fix that?

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5715
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Login via uart without type username and password

Fri Dec 29, 2017 4:49 pm

cloudbu wrote: Hi everyone.
I need send serial command without sending username and password. I tried "Console Autologin" in raspi-config, but still after reboot I have to type username and password.
How fix that?
That's correct and normal behaviour for the serial console/terminal. Whilst there are other types of "serial communication" can you provide us with more detail on what you mean by "I need send serial command" ie. what, exactly, are you trying to do?
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

sparkie777
Posts: 175
Joined: Tue Nov 27, 2012 4:37 am

Re: Login via uart without type username and password

Fri Dec 29, 2017 5:23 pm

for current raspbian/stretch it's sufficient to create a file with this content:

/etc/systemd/system/serial-getty@.service:

Code: Select all

[Unit]
Description=Serial Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

[Service]
ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM -na root
Type=idle
Restart=always
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes

[Install]
WantedBy=getty.target
(this file is effectively a copy of file '/lib/systemd/system/serial-getty@.service' with a minimal change)

now issue:

Code: Select all

systemctl enable serial-getty@ttyAMA0.service
after the next reboot this will automatically log you in on the serial console (UART) as root w/o passwd.
Of course you can replace 'root' by any other valid login name

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5715
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Login via uart without type username and password

Sat Dec 30, 2017 3:06 pm

sparkie777 wrote: for current raspbian/stretch it's sufficient to create a file with this content:

/etc/systemd/system/serial-getty@.service:

Code: Select all

[Unit]
Description=Serial Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

[Service]
ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM -na root
Type=idle
Restart=always
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes

[Install]
WantedBy=getty.target
(this file is effectively a copy of file '/lib/systemd/system/serial-getty@.service' with a minimal change)

now issue:

Code: Select all

systemctl enable serial-getty@ttyAMA0.service
after the next reboot this will automatically log you in on the serial console (UART) as root w/o passwd.
Of course you can replace 'root' by any other valid login name
I suspect, but haven't checked, that that approach is somewhat similar to what raspi-config's "auto-login" option sets up:
http://www.cpmspectrepi.uk/raspberry_pi ... Tools.html (Jessie screenshots, but little/no difference for Stretch).
The OP appears not to desire any form of login - hence my request for further info.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

sparkie777
Posts: 175
Joined: Tue Nov 27, 2012 4:37 am

Re: Login via uart without type username and password

Sat Dec 30, 2017 3:43 pm

FTrevorGowen wrote:
Sat Dec 30, 2017 3:06 pm
The OP appears not to desire any form of login - hence my request for further info.
my solution just provides an instant root shell prompt at the serial console after reboot.

I.e. no user intervention at all is required for this to happen.

I hope that fully serves the OPs purposes :-)

cloudbu
Posts: 3
Joined: Thu Dec 28, 2017 12:38 pm

Re: Login via uart without type username and password

Sat Dec 30, 2017 9:41 pm

Thanks everyone.
I wrote here because I had a problem with typing username and password. And.... gues what?

If you will try send commands before login you need type ONE MORE SIGN to "wake up" the communication before typing "username" (the same like in Windows - before type password you have to click, press enter or something). So, my algoritm is:

Code: Select all

send "\r" (carriage return)
send "username"
wait 1 second
send "password"
Of course that solution is more safety for project and is the best for me :).
Thank you again. See you next time.

Return to “Beginners”