LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-13-2017, 06:17 AM   #1
RandyTech
Member
 
Registered: Oct 2010
Posts: 62

Rep: Reputation: 3
Replace systemd tty1 getty with telnet session


I know it can be done but cannot figure out how and my searches lead only to mass confusion.

I have a Raspberry Debian/Jessie installation. I'm setup with auto-login with GUI disabled so the completed boot leaves me sitting on a command prompt in the tty1 screen. Instead, I want the Raspberry to boot straight into a telnet session connecting to a separate local host computer at a static address, in essence, acting as a dumb terminal into that separate server. (PLEASE!!! No lectures about telnet -- I know already.)

I've researched systemd angles, .bashrc angles, .bash_profile angles, rc.local angles, crontab... I do not necessarily need this to be a systemd solution but I think that would be the cleanest solution. Not opposed to alternative boot script solution either if it can give me an automated telnet connection and login prompt on that separate local server. Ideally the solution would respawn to a fresh telnet login prompt when the user disconnects or telnet login times out. I think I can figure that out if I can just get the initial auto telnet thing working.
 
Old 07-13-2017, 09:01 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Prior to systemd in SysVInit the way to condition specific ports was with /etc/inittab.

Looking for that led to this link post that seems to have ideas I would try were I doing what you are asking. I haven't done any of this myself on systemd.

It's been awhile since I mucked with even inittab but my recollection was that you'd set use a getty definition (which once upon a time were in /etc/gettydefs) and that would simply prompt for login. What you did to login depended on what daemons you were running (e.g. sshd and/or telnetd, sftpd, ftpd etc...) rather than being part of the gettydef itself. If you're already getting login prompts you may wish to focus on starting telnetd.
 
Old 07-15-2017, 12:14 AM   #3
RandyTech
Member
 
Registered: Oct 2010
Posts: 62

Original Poster
Rep: Reputation: 3
Thanks for taking a stab at it MensaWater, but I didn't find any joy there. He starts out talking about a systemd equivalent on the inittab entry for tty1 and apparently ends up running some background process instead. I need to replace the tty1 login prompt with an active telnet session. Systemd
 
Old 07-15-2017, 06:06 AM   #4
RandyTech
Member
 
Registered: Oct 2010
Posts: 62

Original Poster
Rep: Reputation: 3
Got it!
Not a "systemd" solution per say, but I found this reference that led me to an acceptable solution. This was the first reference I found that suggested editing the /etc/profile file.
http://www.opentechguides.com/how-to...uto-start.html

The following is my basic outline. More code will be need to be added to loop around to restart the telnet session when the user logs out or telnet prompt times out, but I'm not going to clutter the basic outline with those details. This is tested and working in both the minimal and full Raspian (Recommended) Debian/Jessie install.


To begin, get your Pi configured to boot into CLI mode with auto-login.
Next, install the telnet package (not included in defaults OS installation):
Code:
sudo apt-get -y install telnet
Now begins the magic trick I was looking for where .bashrc, .bash_profile, rc.local and crontab all failed me:
Code:
sudo vi /etc/profile
Append the bottom of the file with this line and be sure to include the preceding "dot":
Code:
. /opt/dotelnet
That line will invoke your script after the Raspberry reaches the system command prompt. I have no idea what that "dot" is there for but it was in the reference sample so I just followed suite, and it works. (Don't fix it if it ain't broke)


Next you create the script you want to invoke after the auto-login:
Code:
sudo vi /opt/dotelnet
Populate the file with the following code:
Code:
#!/bin/bash
portName=`who am i | awk '{print $2}'`
echo "you are $portName"
case $portName in
  tty1) portName="ok" ;;
  tty2) portName="ok" ;;
  tty3) portName="ok" ;;
  tty4) portName="ok" ;;
  tty5) portName="ok" ;;
  tty6) portName="ok" ;;
esac
if [ "$portName" = "ok" ] ; then
  echo "Entering terminal mode..."
  sleep 1
  /usr/bin/telnet 192.168.1.138
fi
Save it and make the script executable:
Code:
sudo chmod 755 /opt/dotelnet
One last step to see the magic happen:
Code:
sudo reboot
Obvious to some more than others, you might want to change the name and/or location of the "/opt/dotelnet" file. Up to you. And the 192.168.1.138 address will probably need to be adjusted to point to your local host machine.

It should also be noted here, the above solution is invoked not only on the tty1 auto-login session but also works when you login on any of the VT screens, and this should work regardless what user name you use. I am using the default "pi" user.

In case you are asking "why did he use the case esac structure to test for the console screens", it turned out this simpler more elegant code worked perfectly in the full Raspian installation but failed in the minimal Raspian installation. (go figure )
Code:
#!/bin/bash
portName=`who am i | awk '{print $2}'`
echo "you are $portName"
if [ "$portName" = "tty[1-6]" ] ; then
  echo "Entering terminal mode..."
  sleep 1
  /usr/bin/telnet 192.168.1.138
fi
Would be interesting to know why that is. Whatever the case, the script is never invoked when you ssh into the Raspberry.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Canonical to Replace Upstart with systemd for Ubuntu 16.10's Session Startup LXer Syndicated Linux News 0 08-18-2016 05:59 AM
How do I replace systemd init? Pixxt Debian 3 06-22-2014 09:59 AM
systemd for per screen session serafean Linux - Software 0 02-07-2013 10:44 AM
How can I connect to a tty1 session remotely? (centos5.8) odielag Linux - Security 1 09-03-2012 08:56 AM
Telnet session consumes 8KB which is never released after session is terminated NilesBor Linux - Kernel 1 04-24-2009 11:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration