0

I'm trying to figure out the setup of port 23 on an Ubuntu server. It was setup by my predecessor in quite a tricky way and now I need to migrate the functionality to a new machine. I know roughly how it functions, but I don't know the details, which is what I need to know now. The rough functionality is this:

  • Users log in to the server as a regular linux user via port 23 (always with the same user). More detail on this below...
  • Once logged in, they are presented with a prompt for some information
  • They enter information at the prompt and then it logs them out

I can see that the default shell is bash (username and number modified for privacy):

# grep theuser /etc/passwd
theuser:x:1111:1111::/home/theuser:/bin/bash

And I can see that the .bash_profile script redirects the user to the prompts upon login:

$ cat /home/theuser/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/scripts

export PATH
unset USERNAME

/home/theuser/scripts/prompts
exit

So there is no mystery there. However the question I have is how on earth can port 23 be linked to the login prompt of a regular linux user? I know for sure that this is the case because I can login as follows:

$ telnet localhost 23
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
machinename login: theuser
Password:
Last login: Fri Mar 24 14:25:48 CST 2017 from localhost on pts/5
prompt 1:

If I check for processes running on port 23 then I get:

$ netstat -tulpn | grep 23
tcp        0      0 0.0.0.0:23              0.0.0.0:*               LISTEN      2222/inetd

So the connection is handled by inetd. But that doesn't help me out because I don't know what inetd is doing. If I look in /etc/inetd.conf then I see the following line:

telnet      stream  tcp nowait  root    /usr/sbin/tcpd  /usr/sbin/in.telnetd

But that's not much help. I already knew telnet was running on this machine. I need to know how telnet is configured to redirect the user to a login prompt.

  • inetd listens to TCP (or UDP) ports, and hands down connections to other special crafted programs (typically named in.<mumble>), which in turn simply use stdin / stdout instead of dealing with network communications themselves. One such special crafted program is in.telnetd, which is the telnet server. See man inetd and man in.telnetd for more information. – Satō Katsura Mar 24 '17 at 7:08
2

Having a TELNET server listening on TCP port 23 is not "tricky". It is normal (as long as one discounts the abnormality of using TELNET at all in this century). That is the well known port number for TELNET service.

And in.telnetd is not "configured" to "redirect" the user to a login prompt. Presenting a login interface to connected clients is what it does. Its manual page (q.v.) is quite explicit:

Telnetd operates by allocating a pseudo-terminal device […] for a client, then creating a login process which has the slave side of the pseudo-terminal as stdin, stdout and stderr. Telnetd manipulates the master side of the pseudo-terminal, implementing the telnet protocol and passing characters between the remote client and the login process.

The login process is running the login program, presenting that login prompt.

  • its tricky because this is the first i (and i suspect many others of my age) have ever heard of being able to log in to linux using telnet. though now i have done some reading on it, i'm getting a better picture of how this all works. – mulllhausen Mar 24 '17 at 22:39
  • @mulllhausen You never heard of this configuration because everybody has been discouraging its use for the past ~25 years. In the vast majority of cases it's more appropriate to use ssh instead. – Satō Katsura Mar 25 '17 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.